Mon, 14 Jul 2014 13:20:03 +0200
fixed stream copy bug + fixed doc issues in mempool
ucx/mempool.h | file | annotate | diff | comparison | revisions | |
ucx/utils.c | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/mempool.h Mon Jul 14 12:45:48 2014 +0200 1.2 +++ b/ucx/mempool.h Mon Jul 14 13:20:03 2014 +0200 1.3 @@ -121,7 +121,7 @@ 1.4 /** 1.5 * Allocates a pooled memory array. 1.6 * 1.7 - * The contents of the allocated memory is set to zero. 1.8 + * The content of the allocated memory is set to zero. 1.9 * 1.10 * @param pool the memory pool 1.11 * @param nelem amount of elements to allocate 1.12 @@ -142,7 +142,7 @@ 1.13 * @param pool the memory pool 1.14 * @param ptr a pointer to the memory that shall be reallocated 1.15 * @param n the new size of the memory 1.16 - * @return a pointer to the the location of the memory 1.17 + * @return a pointer to the new location of the memory 1.18 * @see ucx_allocator_realloc() 1.19 */ 1.20 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
2.1 --- a/ucx/utils.c Mon Jul 14 12:45:48 2014 +0200 2.2 +++ b/ucx/utils.c Mon Jul 14 13:20:03 2014 +0200 2.3 @@ -54,18 +54,22 @@ 2.4 return 0; 2.5 } 2.6 2.7 + char *lbuf; 2.8 size_t ncp = 0; 2.9 - if (!buf) { 2.10 - buf = (char*)malloc(bufsize); 2.11 - if(buf == NULL) { 2.12 + 2.13 + if(buf) { 2.14 + lbuf = buf; 2.15 + } else { 2.16 + lbuf = (char*)malloc(bufsize); 2.17 + if(lbuf == NULL) { 2.18 return 0; 2.19 } 2.20 } 2.21 2.22 size_t r; 2.23 size_t rn = bufsize > n ? n : bufsize; 2.24 - while((r = readfnc(buf, 1, rn, src)) != 0) { 2.25 - r = writefnc(buf, 1, r, dest); 2.26 + while((r = readfnc(lbuf, 1, rn, src)) != 0) { 2.27 + r = writefnc(lbuf, 1, r, dest); 2.28 ncp += r; 2.29 n -= r; 2.30 rn = bufsize > n ? n : bufsize; 2.31 @@ -74,7 +78,10 @@ 2.32 } 2.33 } 2.34 2.35 - free(buf); 2.36 + if (lbuf != buf) { 2.37 + free(lbuf); 2.38 + } 2.39 + 2.40 return ncp; 2.41 } 2.42