[PATCH 12/19] ui-snapshot.c: tidy up memory management in write_archive_type
John Keeping
john at keeping.me.uk
Sun Apr 7 11:30:03 CEST 2013
- Use a strbuf instead of a fixed-size buffer
- Free the argv_array when we're done with it
Signed-off-by: John Keeping <john at keeping.me.uk>
---
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
More information about the CGit
mailing list