Re: [PATCH 11/23] builtin/stash: fix various trivial memory leaks
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jul 31, 2024, 16:40 UTC
- Message-ID
- <Zqpo/8HnUbgF5ZmQ@nand.local>
- In-Reply-To
- <a4b3ca49c9724b79ca695d0db8e45be663a46434.1721995576.git.ps@pks.im>
On Fri, Jul 26, 2024 at 02:16:12PM +0200, Patrick Steinhardt wrote:
Show 18 quoted lines
> @@ -1892,5 +1895,16 @@ int cmd_stash(int argc, const char **argv, const char *prefix) > /* Assume 'stash push' */ > strvec_push(&args, "push"); > strvec_pushv(&args, argv); > - return !!push_stash(args.nr, args.v, prefix, 1); > + > + /* > + * `push_stash()` ends up modifying the array, which causes memory > + * leaks if we didn't copy the array here. > + */ > + DUP_ARRAY(args_copy, args.v, args.nr); > + > + ret = !!push_stash(args.nr, args_copy, prefix, 1); > + > + strvec_clear(&args); > + free(args_copy); > + return ret; > }
OK, so this is the same pattern as we saw in the third patch of this series. I agree with Junio's comments in that sub-thread, but also that they are out-of-scope for the present series ;-).
Looking good.
Thanks, Taylor