]> git.tue.mpg.de Git - paraslash.git/commitdiff
Fix memory leak in btr_splice_out_node().
authorAndre Noll <maan@systemlinux.org>
Tue, 31 Dec 2013 13:29:16 +0000 (13:29 +0000)
committerAndre Noll <maan@systemlinux.org>
Sat, 3 May 2014 12:08:00 +0000 (14:08 +0200)
Commit 072391fc (Improve btr_splice_out_node(), 2013-03) modified this
function to take a pointer to a buffer tree node pointer so that the
node pointer can be invalidated after it is spliced out. However, this
also means the caller can no longer free its resources. Hence we must
free the btrn in btr_splice_out_node() in order to avoid memory leaks.

buffer_tree.c

index 5afa3ad3deda281415cfd172af0c13092b95ad67..44b73c946d1fc6127aba2b1e9e31c206b67ba18c 100644 (file)
@@ -771,6 +771,12 @@ void btr_drain(struct btr_node *btrn)
                btr_drop_buffer_reference(br);
 }
 
+static void btr_free_node(struct btr_node *btrn)
+{
+       free(btrn->name);
+       free(btrn);
+}
+
 /**
  * Remove a node from a buffer tree.
  *
@@ -798,8 +804,7 @@ void btr_remove_node(struct btr_node **btrnp)
        btr_drain(btrn);
        if (btrn->parent)
                list_del(&btrn->node);
-       free(btrn->name);
-       free(btrn);
+       btr_free_node(btrn);
 out:
        *btrnp = NULL;
 }
@@ -862,6 +867,7 @@ void btr_splice_out_node(struct btr_node **btrnp)
                        list_del(&ch->node);
        }
        assert(list_empty(&btrn->children));
+       btr_free_node(btrn);
        *btrnp = NULL;
 }