From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Sun, 7 Apr 2013 10:30:03 +0100 Subject: [PATCH 12/19] ui-snapshot.c: tidy up memory management in write_archive_type In-Reply-To: References: Message-ID: <4d4111a69764181b36cee275fe25ab23fd9796fb.1365326321.git.john@keeping.me.uk> - Use a strbuf instead of a fixed-size buffer - Free the argv_array when we're done with it Signed-off-by: John Keeping --- ui-snapshot.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ui-snapshot.c b/ui-snapshot.c index a47884e..2d47676 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -15,14 +15,21 @@ static int write_archive_type(const char *format, const char *hex, const char *prefix) { struct argv_array argv = ARGV_ARRAY_INIT; + int result; argv_array_push(&argv, "snapshot"); argv_array_push(&argv, format); if (prefix) { + struct strbuf buf = STRBUF_INIT; + strbuf_addstr(&buf, prefix); + strbuf_addch(&buf, '/'); argv_array_push(&argv, "--prefix"); - argv_array_push(&argv, fmt("%s/", prefix)); + argv_array_push(&argv, buf.buf); + strbuf_release(&buf); } argv_array_push(&argv, hex); - return write_archive(argv.argc, argv.argv, NULL, 1, NULL, 0); + result = write_archive(argv.argc, argv.argv, NULL, 1, NULL, 0); + argv_array_clear(&argv); + return result; } static int write_tar_archive(const char *hex, const char *prefix) -- 1.8.2.692.g17a9715