diff --git a/main.c b/main.c index 8d49cbe..24564fd 100644 --- a/main.c +++ b/main.c @@ -309,9 +309,10 @@ void clear_params(void) if (params.spos) { for (int i = 0; i < params.spos_n; i++) { struct spos s = params.spos[i]; - if (!s.data) continue; - free(s.data); - s.data = 0; + if (s.data != 0) { + free(s.data); + s.data = 0;; + } } free(params.spos); params.spos = 0; @@ -323,7 +324,7 @@ void clear_params(void) free(s.ip_options); s.ip_options = ip_option; } - if (!s.parts) { + if (s.parts != 0) { free(s.parts); s.parts = 0; } diff --git a/mpool.c b/mpool.c index 49c6f3d..8efcb08 100644 --- a/mpool.c +++ b/mpool.c @@ -117,7 +117,7 @@ void mem_delete(struct mphdr *hdr, int pos) void mem_destroy(struct mphdr *hdr) { - for (int i = 0; i < hdr->count; i++) { + for (int i = 0; i < hdr->count && hdr->values; i++) { struct elem *e = hdr->values[i]; if (!e) { continue; @@ -125,4 +125,6 @@ void mem_destroy(struct mphdr *hdr) free(e); hdr->values[i] = 0; } + memset(hdr, 0, sizeof(*hdr)); + free(hdr); } \ No newline at end of file