[augeas-devel] Memory leak in create

David Lutterkort lutter at redhat.com
Tue Jul 20 17:47:25 UTC 2010


On Tue, 2010-07-20 at 10:19 -0400, Francis Giraldeau wrote:
> There were a small memory leak while doing a create, where a split
> doesn't match. The patch attached fixes the issue. 

Nice catch. I made a minor change in the way cleanup is done. In
general, I prefer that if there is cleanup on successful completion of a
function, that that only goes into one place, and that the error label
only does error-specific cleanup and then jumps to the general cleanup. 

That makes it less likely that in the future we'll forget to do
additional cleanup on the error path as well as the success path. The
second hunk of your patch as committed is now:

@@ -245,9 +245,14 @@ static struct split *split_concat(struct state *state, struct lens *lens) {
         reg += 1 + regexp_nsub(lens->children[i]->atype);
     }
     assert(reg < regs.num_regs);
+ done:
     free(regs.start);
     free(regs.end);
     return split;
+ error:
+    free_split(split);
+    split = NULL;
+    goto done;
 }





More information about the augeas-devel mailing list