From f15858adf036b3010895526eaf6d1b9711d48bc9 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 19 Apr 2018 13:38:55 +0200 Subject: [PATCH] fix leaks --- src/data.c | 13 +++++++------ src/parser.c | 2 +- src/types/decl_file.c | 1 - src/validate.c | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/data.c b/src/data.c index 193f49c..4f7168f 100644 --- a/src/data.c +++ b/src/data.c @@ -160,16 +160,17 @@ void psi_data_dtor(struct psi_data *data) void psi_data_dump(int fd, struct psi_data *D) { + size_t i = 0; + char *libname; + if (D->file.filename) { size_t i = 0; char *libname; dprintf(fd, "// filename=%s (%u errors)\n", D->file.filename, D->errors); - while (psi_plist_get(D->file.libnames, i++, &libname)) { - dprintf(fd, "lib \"%s\";\n", libname); - } - } else { - dprintf(fd, "// builtin predef\n"); + } + while (psi_plist_get(D->file.libnames, i++, &libname)) { + dprintf(fd, "lib \"%s\";\n", libname); } if (psi_plist_count(D->types)) { size_t i = 0; @@ -234,7 +235,7 @@ void psi_data_dump(int fd, struct psi_data *D) while (psi_plist_get(D->decls, i++, &decl)) { psi_decl_dump(fd, decl); - dprintf(fd, "\n"); + dprintf(fd, "// %p \n", decl->sym); } dprintf(fd, "\n"); } diff --git a/src/parser.c b/src/parser.c index 07e3dfc..148d74c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,4 +1,4 @@ -/* Generated by re2c 1.0.3 on Wed Apr 18 08:03:43 2018 */ +/* Generated by re2c 1.0.3 on Wed Apr 18 08:08:41 2018 */ #line 1 "src/parser.re" /******************************************************************************* Copyright (c) 2016, Michael Wallner . diff --git a/src/types/decl_file.c b/src/types/decl_file.c index c8622db..df07579 100644 --- a/src/types/decl_file.c +++ b/src/types/decl_file.c @@ -79,7 +79,6 @@ bool psi_decl_file_validate(struct psi_data *dst, struct psi_data *src) return false; } - libname = strdup(libname); dst->file.libnames = psi_plist_add(dst->file.libnames, &libname); dst->file.dlopened = psi_plist_add(dst->file.dlopened, &dlopened); } diff --git a/src/validate.c b/src/validate.c index 1d55b13..e7bceaf 100644 --- a/src/validate.c +++ b/src/validate.c @@ -223,5 +223,30 @@ bool psi_validate(struct psi_validate_scope *scope, psi_validate_list(scope, dst, &consts, psi_validate_const); psi_validate_list(scope, dst, &impls, psi_validate_impl); + if (types.cur != types.src) { + psi_plist_free(types.cur); + } + if (structs.cur != structs.src) { + psi_plist_free(structs.cur); + } + if (unions.cur != unions.src) { + psi_plist_free(unions.cur); + } + if (enums.cur != enums.src) { + psi_plist_free(enums.cur); + } + if (vars.cur != vars.src) { + psi_plist_free(vars.cur); + } + if (decls.cur != decls.src) { + psi_plist_free(decls.cur); + } + if (consts.cur != consts.src) { + psi_plist_free(consts.cur); + } + if (impls.cur != impls.src) { + psi_plist_free(impls.cur); + } + return true; } -- 2.30.2