From 1c7ffee4a2c42d80f519654b3856cb81792d8af8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 30 May 2015 16:42:25 +0200 Subject: [PATCH] misc: fix a few minor issues found by static code analysis. --- src/libzzuf/debug.c | 14 ++++++++------ src/zzat.c | 1 + src/zzuf.c | 2 +- test/zzone.c | 2 ++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libzzuf/debug.c b/src/libzzuf/debug.c index a674f3c..dc3cb3b 100644 --- a/src/libzzuf/debug.c +++ b/src/libzzuf/debug.c @@ -82,9 +82,9 @@ void zzuf_debug(char const *format, ...) int ret = _vsnprintf(buf, sizeof(buf), format, args); if (ret <= 0) - return; /* if _snprintf failed, we send nothing */ + goto abort; /* if _snprintf failed, we send nothing */ if (buf[0] == '\0') - return; /* if buf is empty, we don't bother to send it to zzuf */ + goto abort; /* if buf is empty, we don't send it */ /* If len >= count, no null-terminator is appended, so we need to * erase the last character */ @@ -96,8 +96,9 @@ void zzuf_debug(char const *format, ...) WriteFile(dbg_hdl, buf, ret, &written, NULL); zzuf_mutex_unlock(&debug_mutex); } + fflush(NULL); /* flush all streams */ +abort: va_end(args); - fflush(NULL); /* flush all streams to make sure zzuf gotta catch 'em all */ } void zzuf_debug2(char const *format, ...) @@ -112,9 +113,9 @@ void zzuf_debug2(char const *format, ...) int ret = _vsnprintf(buf, sizeof(buf), format, args); if (ret <= 0) - return; /* if _snprintf failed, we send nothing */ + goto abort; /* if _snprintf failed, we send nothing */ if (buf[0] == '\0') - return; /* if buf is empty, we don't bother to send it to zzuf */ + goto abort; /* if buf is empty, we don't send it */ /* If len >= count, no null-terminator is appended, so we need to * erase the last character */ @@ -126,8 +127,9 @@ void zzuf_debug2(char const *format, ...) WriteFile(dbg_hdl, buf, ret, &written, NULL); zzuf_mutex_unlock(&debug_mutex); } + fflush(NULL); /* flush all streams */ +abort: va_end(args); - fflush(NULL); /* flush all streams to make sure zzuf gotta catch 'em all */ } #else void zzuf_debug(char const *format, ...) diff --git a/src/zzat.c b/src/zzat.c index f9c4043..7acfec6 100644 --- a/src/zzat.c +++ b/src/zzat.c @@ -417,6 +417,7 @@ static int run(char const *sequence, char const *file) if (nloops == 0) { fprintf(stderr, "E: zzat: ')' outside a loop\n"); + free(tmp); return EXIT_FAILURE; } if (loops[nloops - 1].count == 1 || finish) diff --git a/src/zzuf.c b/src/zzuf.c index e71a3f0..c46b84b 100644 --- a/src/zzuf.c +++ b/src/zzuf.c @@ -739,7 +739,7 @@ static void spawn_children(zzuf_opts_t *opts) continue; #ifdef _WIN32 - sprintf(tmpname, "%s/zzuf.$i.XXXXXX", tmpdir, GetCurrentProcessId()); + sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, GetCurrentProcessId()); int fdout = _open(mktemp(tmpname), _O_RDWR, 0600); #else sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, (int)getpid()); diff --git a/test/zzone.c b/test/zzone.c index 92c0236..84243cd 100644 --- a/test/zzone.c +++ b/test/zzone.c @@ -47,6 +47,8 @@ int main(int argc, char *argv[]) uint8_t *tmp = malloc(size); if (!buf || !tmp) { + free(buf); + free(tmp); fprintf(stderr, "zzone: cannot alloc memory\n"); return EXIT_FAILURE; }