From: Yu Watanabe Date: Sat, 6 Mar 2021 01:10:31 +0000 (+0900) Subject: format-table: fix potentail memleak and invalid-free X-Git-Tag: v248-rc3~43 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f6b54e5280c60bfd8a861fba71d3c20ffae7cc9d;p=thirdparty%2Fsystemd.git format-table: fix potentail memleak and invalid-free --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index fdb5887a1aa..ae56cd3d678 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1317,9 +1317,9 @@ static int table_data_compare(const size_t *a, const size_t *b, Table *t) { } static char* format_strv_width(char **strv, size_t column_width) { + _cleanup_free_ char *buf = NULL; /* buf must be freed after f */ _cleanup_fclose_ FILE *f = NULL; size_t sz = 0; - _cleanup_free_ char *buf = NULL; f = open_memstream_unlocked(&buf, &sz); if (!f) @@ -2320,8 +2320,8 @@ int table_print(Table *t, FILE *f) { } int table_format(Table *t, char **ret) { + _cleanup_free_ char *buf = NULL; _cleanup_fclose_ FILE *f = NULL; - char *buf = NULL; size_t sz = 0; int r; @@ -2335,7 +2335,7 @@ int table_format(Table *t, char **ret) { f = safe_fclose(f); - *ret = buf; + *ret = TAKE_PTR(buf); return 0; }