]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/kmem.c
xfs: fix transaction leak on remote attr set/remove failure
[thirdparty/xfsprogs-dev.git] / libxfs / kmem.c
index 5d3b9b64dc1c9a40cbfa98b850a5d86350043d75..5f65d97c9907525ee5067e6809de03822a00cacb 100644 (file)
@@ -1,6 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 
 
-#include <xfs/libxfs.h>
+#include "libxfs_priv.h"
 
 /*
  * Simple memory interface
@@ -13,7 +14,7 @@ kmem_zone_init(int size, char *name)
 
        if (ptr == NULL) {
                fprintf(stderr, _("%s: zone init failed (%s, %d bytes): %s\n"),
-                       progname, name, (int)sizeof(kmem_zone_t), 
+                       progname, name, (int)sizeof(kmem_zone_t),
                        strerror(errno));
                exit(1);
        }
@@ -23,6 +24,20 @@ kmem_zone_init(int size, char *name)
        return ptr;
 }
 
+int
+kmem_zone_destroy(kmem_zone_t *zone)
+{
+       int     leaked = 0;
+
+       if (getenv("LIBXFS_LEAK_CHECK") && zone->allocated) {
+               leaked = 1;
+               fprintf(stderr, "zone %s freed with %d items allocated\n",
+                               zone->zone_name, zone->allocated);
+       }
+       free(zone);
+       return leaked;
+}
+
 void *
 kmem_zone_alloc(kmem_zone_t *zone, int flags)
 {
@@ -70,7 +85,7 @@ kmem_zalloc(size_t size, int flags)
 }
 
 void *
-kmem_realloc(void *ptr, size_t new_size, size_t old_size, int flags)
+kmem_realloc(void *ptr, size_t new_size, int flags)
 {
        ptr = realloc(ptr, new_size);
        if (ptr == NULL) {
@@ -80,4 +95,3 @@ kmem_realloc(void *ptr, size_t new_size, size_t old_size, int flags)
        }
        return ptr;
 }
-