My version of Matt's improvements related to missing source args:
[rsync/rsync.git] / lib / pool_alloc.c
index 05b182c..292167a 100644 (file)
@@ -52,7 +52,7 @@ pool_create(size_t size, size_t quantum, void (*bomb)(const char *), int flags)
        pool->size = size       /* round extent size to min alignment reqs */
            ? (size + MINALIGN - 1) & ~(MINALIGN - 1)
            : POOL_DEF_EXTENT;
-       if (pool->flags & POOL_INTERN) {
+       if (flags & POOL_INTERN) {
                pool->size -= sizeof (struct pool_extent);
                flags |= POOL_APPEND;
        }
@@ -226,15 +226,9 @@ pool_free_old(alloc_pool_t p, void *addr)
        struct alloc_pool *pool = (struct alloc_pool *)p;
        struct pool_extent *cur, *prev, *next;
 
-       if (!pool)
+       if (!pool || !addr)
                return;
 
-       if (!addr) {
-               if (!pool->extents)
-                       return;
-               addr = PTR_ADD(pool->extents->start, pool->extents->free);
-       }
-
        for (prev = NULL, cur = pool->extents; cur; prev = cur, cur = cur->next) {
                if (addr >= cur->start
                    && addr < PTR_ADD(cur->start, pool->size))
@@ -261,6 +255,7 @@ pool_free_old(alloc_pool_t p, void *addr)
                                cur->free -= skew;
                        }
                        next = cur->next;
+                       cur->next = NULL;
                }
        } else {
                next = cur->next;
@@ -300,24 +295,30 @@ pool_boundary(alloc_pool_t p, size_t len)
 }
 
 #define FDPRINT(label, value) \
-       snprintf(buf, sizeof buf, label, value), \
-       write(fd, buf, strlen(buf))
+       do { \
+               int len = snprintf(buf, sizeof buf, label, value); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
 
 #define FDEXTSTAT(ext) \
-       snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
-               (long) ext->free, \
-               (long) ext->bound), \
-       write(fd, buf, strlen(buf))
-
-void
+       do { \
+               int len = snprintf(buf, sizeof buf, "  %12ld  %5ld\n", \
+                                  (long)ext->free, (long)ext->bound); \
+               if (write(fd, buf, len) != len) \
+                       ret = -1; \
+       } while (0)
+
+int
 pool_stats(alloc_pool_t p, int fd, int summarize)
 {
        struct alloc_pool *pool = (struct alloc_pool *) p;
        struct pool_extent      *cur;
        char buf[BUFSIZ];
+       int ret = 0;
 
        if (!pool)
-               return;
+               return ret;
 
        FDPRINT("  Extent size:       %12ld\n", (long)  pool->size);
        FDPRINT("  Alloc quantum:     %12ld\n", (long)  pool->quantum);
@@ -329,13 +330,16 @@ pool_stats(alloc_pool_t p, int fd, int summarize)
        FDPRINT("  Bytes freed:       %12.0f\n", (double) pool->b_freed);
 
        if (summarize)
-               return;
+               return ret;
 
        if (!pool->extents)
-               return;
+               return ret;
 
-       write(fd, "\n", 1);
+       if (write(fd, "\n", 1) != 1)
+               ret = -1;
 
        for (cur = pool->extents; cur; cur = cur->next)
                FDEXTSTAT(cur);
+
+       return ret;
 }