[PATCH 4/6] cgit_print_tree(): Free curr_rev after usage

Jason A. Donenfeld Jason at zx2c4.com
Tue Mar 5 02:36:46 CET 2013


On Mon, Mar 4, 2013 at 7:25 AM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
>         if (path == NULL) {
>                 ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx);
> +               free(walk_tree_ctx.curr_rev);
>                 return;
>         }
>
>         read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
>         if (walk_tree_ctx.state == 1)
>                 ls_tail();
> +       free(walk_tree_ctx.curr_rev);
>  }

For clean-up code that needs to be repeated for different error paths,
I generally prefer to have a "goto cleanup;" line, in the style of the
kernel. This function is simple enough that it's not a huge deal, but
it can help avoid bugs in the future when different folks are
modifying the function.




More information about the CGit mailing list