Re: [PATCHv4 10/12] notes.c: Implement simple memory pooling of leaf nodes
- From
Alex Riesen <raa.lkml@gmail.com>
- Date
- Aug 27, 2009, 07:39 UTC
- Message-ID
- <81b0412b0908270039l7a937c3bmd745274c71526ce1@mail.gmail.com>
- In-Reply-To
- <1251337437-16947-11-git-send-email-johan@herland.net>
On Thu, Aug 27, 2009 at 03:43, Johan Herland<johan@herland.net> wrote:
> When allocating a new memory pool, the older pool is leaked, but this is > no worse than the current situation, where (pretty much) all leaf_nodes > are leaked anyway.
Could you return the unused nodes back into tghe mempool? By making the pool a preallocated list, perhaps?
And then it is trivial to provide a deallocation function for the mempool, which something really concerned about the memleak can call (like when or if libgit get more usable in an application context).
Show 5 quoted lines
> @@ -95,7 +112,6 @@ static struct leaf_node *note_tree_find(struct int_node *tree, unsigned char n, > /* unpack tree and resume search */ > tree->a[i] = NULL; > load_subtree(l, tree, n); > - free(l);
free_leaf_node(l), which returns the node into mempool
Show 8 quoted lines
> return note_tree_find(tree, n, key_sha1); > } > break; > @@ -118,7 +134,6 @@ static struct leaf_node *note_tree_find(struct int_node *tree, unsigned char n, > /* unpack tree and resume search */ > tree->a[0] = NULL; > load_subtree(l, tree, n); > - free(l);
free_leaf_node(l);
> return note_tree_find(tree, n, key_sha1); > } > return NULL;