From 0f0c1d2c2b2d90ebae8fd89e51b9acc52769ec64 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 28 Jun 2023 20:37:50 +0100 Subject: [PATCH] Fix several minor memory leaks --- src/diag.c | 5 +++-- src/jit/jit-ffi.c | 8 +++----- src/util.h | 2 +- src/vlog/vlog-parse.y | 1 + 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/diag.c b/src/diag.c index fbf5b24f..12c8ac2c 100644 --- a/src/diag.c +++ b/src/diag.c @@ -946,12 +946,12 @@ static void diag_format_full(diag_t *d, FILE *f) void diag_femit(diag_t *d, FILE *f) { if (d->suppress) - return; + goto cleanup; else if (consumer != NULL && d->level > DIAG_DEBUG) (*consumer)(d); else if (d->level == DIAG_DEBUG && opt_get_int(OPT_UNIT_TEST) && diag_has_message(d)) - return; + goto cleanup; else { // The stderr and stdout streams are often redirected to the same // file so ensure that the output appears in a logical order @@ -977,6 +977,7 @@ void diag_femit(diag_t *d, FILE *f) if (is_error && relaxed_add(&n_errors, 1) == error_limit) fatal("too many errors, giving up"); + cleanup: for (int i = 0; i < d->hints.count; i++) free(d->hints.items[i].text); ACLEAR(d->hints); diff --git a/src/jit/jit-ffi.c b/src/jit/jit-ffi.c index ec742290..ff8e2910 100644 --- a/src/jit/jit-ffi.c +++ b/src/jit/jit-ffi.c @@ -158,11 +158,9 @@ void jit_ffi_call(jit_foreign_t *ff, jit_scalar_t *args) aptrs[ff->nargs] = &up; if (ff->ptr == NULL) { - LOCAL_TEXT_BUF tb = tb_new(); - tb_istr(tb, ff->sym); - - if ((ff->ptr = ffi_find_symbol(NULL, tb_get(tb))) == NULL) - jit_msg(NULL, DIAG_FATAL, "foreign function %s not found", tb_get(tb)); + const char *sym = istr(ff->sym); + if ((ff->ptr = ffi_find_symbol(NULL, sym)) == NULL) + jit_msg(NULL, DIAG_FATAL, "foreign function %s not found", sym); } intmax_t result; diff --git a/src/util.h b/src/util.h index a3a640a1..e64442d1 100644 --- a/src/util.h +++ b/src/util.h @@ -431,7 +431,7 @@ void list_clear(ptr_list_t *l); } while (0) #define UNPACK_BE32(b) \ - ((b)[0] << 24 | (b)[1] << 16 | (b)[2] << 8 | (b)[3]) + ((unsigned)(b)[0] << 24 | (b)[1] << 16 | (b)[2] << 8 | (b)[3]) #define PACK_BE32(u) \ ((u) >> 24) & 0xff, ((u) >> 16) & 0xff, ((u) >> 8) & 0xff, (u) & 0xff diff --git a/src/vlog/vlog-parse.y b/src/vlog/vlog-parse.y index 38666308..5933ff67 100644 --- a/src/vlog/vlog-parse.y +++ b/src/vlog/vlog-parse.y @@ -550,6 +550,7 @@ decimal_number: tUNSIGNED $$ = vlog_new(V_NUMBER); vlog_set_loc($$, &@$); vlog_set_number($$, number_new($1)); + free($1); } ; -- 2.39.2