fixed stream copy bug + fixed doc issues in mempool

Mon, 14 Jul 2014 13:20:03 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 14 Jul 2014 13:20:03 +0200
changeset 181
1e9012ad8215
parent 179
ee25d79a4187
child 182
998bf7c643b4

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
--- a/ucx/mempool.h	Mon Jul 14 12:45:48 2014 +0200
+++ b/ucx/mempool.h	Mon Jul 14 13:20:03 2014 +0200
@@ -121,7 +121,7 @@
 /**
  * Allocates a pooled memory array.
  * 
- * The contents of the allocated memory is set to zero.
+ * The content of the allocated memory is set to zero.
  * 
  * @param pool the memory pool
  * @param nelem amount of elements to allocate
@@ -142,7 +142,7 @@
  * @param pool the memory pool
  * @param ptr a pointer to the memory that shall be reallocated
  * @param n the new size of the memory
- * @return a pointer to the the location of the memory
+ * @return a pointer to the new location of the memory
  * @see ucx_allocator_realloc()
  */
 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
--- a/ucx/utils.c	Mon Jul 14 12:45:48 2014 +0200
+++ b/ucx/utils.c	Mon Jul 14 13:20:03 2014 +0200
@@ -54,18 +54,22 @@
         return 0;
     }
     
+    char *lbuf;    
     size_t ncp = 0;
-    if (!buf) {
-        buf = (char*)malloc(bufsize);
-        if(buf == NULL) {
+    
+    if(buf) {
+        lbuf = buf;
+    } else {
+        lbuf = (char*)malloc(bufsize);
+        if(lbuf == NULL) {
             return 0;
         }
     }
     
     size_t r;
     size_t rn = bufsize > n ? n : bufsize;
-    while((r = readfnc(buf, 1, rn, src)) != 0) {
-        r = writefnc(buf, 1, r, dest);
+    while((r = readfnc(lbuf, 1, rn, src)) != 0) {
+        r = writefnc(lbuf, 1, r, dest);
         ncp += r;
         n -= r;
         rn = bufsize > n ? n : bufsize;
@@ -74,7 +78,10 @@
         }
     }
     
-    free(buf);
+    if (lbuf != buf) {
+        free(lbuf);
+    }
+    
     return ncp;
 }
 

mercurial