builtin/: add UNLEAKs
PATCH 1/1 builtin/: add UNLEAKs
Add some UNLEAKs where we are about to return from cmd_*. UNLEAK the variables in the same order as we've declared them. While addressing msg in builtin/tag.c, convert the existing strbuf_release() calls as well.
--- builtin/checkout.c | 1 + builtin/diff-index.c | 1 + builtin/diff.c | 3 +++ builtin/name-rev.c | 1 + builtin/tag.c | 9 +++++---- 5 files changed, 11 insertions(+), 4 deletions(-)
builtin/checkout.c +1 -0
@@ -1298,6 +1298,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)strbuf_release (&buf); } +UNLEAK (opts);if (opts.patch_mode || opts.pathspec.nr)return checkout_paths (&opts, new.name);else
builtin/diff-index.c +1 -0
@@ -56,5 +56,6 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)return -1 ; } result =run_diff_index (&rev, cached); +UNLEAK (rev);return diff_result_code (&rev.diffopt, result); }
builtin/diff.c +3 -0
@@ -464,5 +464,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) result =diff_result_code (&rev.diffopt, result);if (1 < rev.diffopt.skip_stat_unmatch)refresh_index_quietly (); +UNLEAK (rev); +UNLEAK (ent); +UNLEAK (blob);return result; }
builtin/name-rev.c +1 -0
@@ -494,5 +494,6 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) always, allow_undefined, data.name_only); } +UNLEAK (revs);return 0 ; }
builtin/tag.c +5 -4
@@ -552,9 +552,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)if (force && !is_null_oid (&prev) &&oidcmp (&prev, &object))printf (_ ("Updated tag '%s' (was %s)\n" ), tag,find_unique_abbrev (prev.hash,DEFAULT_ABBREV )); -strbuf_release (&err); -strbuf_release (&buf); -strbuf_release (&ref); -strbuf_release (&reflog_msg); +UNLEAK (buf); +UNLEAK (ref); +UNLEAK (reflog_msg); +UNLEAK (msg); +UNLEAK (err);return 0 ; }
Signature · 1 line
2.14.2.666.gea220ee40
Quoted 2 lines · Martin Ågren
... While addressing
msginbuiltin/tag.c, convert the existingstrbuf_release()calls as well.
That part of this patch made me raise eyebrows a bit but only slightly. We are about to leave the function to exit anyway, and all the other that got new UNLEAK(var) at the end are doing the same thing.
So overall I think this patch makes sense. Thanks.
Quoted 4 lines · Martin Ågren
Add some UNLEAKs where we are about to return from
cmd_*. UNLEAK the variables in the same order as we've declared them. While addressingmsginbuiltin/tag.c, convert the existingstrbuf_release()calls as well.
It might have raised Junio's eyebrows less to say something like:
...convert the existing strbuf_release() calls as well (they're not wrong, but they also accomplish nothing and create an inconsistency with the UNLEAKed variables).
That aside, the patch looks good.
builtin/checkout.c int cmd_checkout(int argc, const char **argv, const char *prefix) · line 1304
Quoted 12 lines
builtin/checkout.c +1
-0@@ -1298,6 +1298,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)strbuf_release (&buf); } +UNLEAK (opts);if (opts.patch_mode || opts.pathspec.nr)return checkout_paths (&opts, new.name);else
Seeing hunks like this makes me happy with the UNLEAK() solution. It would have been a real pain to do this via actual freeing.
-Peff
Quoted 7 lines · Jeff King
Quoted 4 lines · Martin Ågren
Add some UNLEAKs where we are about to return from
cmd_*. UNLEAK the variables in the same order as we've declared them. While addressingmsginbuiltin/tag.c, convert the existingstrbuf_release()calls as well.
Quoted 5 lines
It might have raised Junio's eyebrows less to say something like:
...convert the existing
strbuf_release()calls as well (they're not wrong, but they also accomplish nothing and create an inconsistency with the UNLEAKed variables).
Most likely yes. Sorry about that. I have yet to be critiqued for writing *too much* in a commit message. That should tell me something.
Quoted 2 lines
Seeing hunks like this makes me happy with the
UNLEAK()solution. It would have been a real pain to do this via actual freeing.
Yes, I was very happy to have it handy. :-)
Martin
Quoted 4 lines · Martin Ågren
Quoted 2 lines
Seeing hunks like this makes me happy with the
UNLEAK()solution. It would have been a real pain to do this via actual freeing.Yes, I was very happy to have it handy. :-)
OK, let's merge this to 'next', then.