fix mem_destroy, clear_params

This commit is contained in:
ruti 2024-03-26 23:47:01 +03:00
parent d4e3ac5a85
commit b0277dba6b
2 changed files with 8 additions and 5 deletions

9
main.c
View file

@ -309,9 +309,10 @@ void clear_params(void)
if (params.spos) { if (params.spos) {
for (int i = 0; i < params.spos_n; i++) { for (int i = 0; i < params.spos_n; i++) {
struct spos s = params.spos[i]; struct spos s = params.spos[i];
if (!s.data) continue; if (s.data != 0) {
free(s.data); free(s.data);
s.data = 0; s.data = 0;;
}
} }
free(params.spos); free(params.spos);
params.spos = 0; params.spos = 0;
@ -323,7 +324,7 @@ void clear_params(void)
free(s.ip_options); free(s.ip_options);
s.ip_options = ip_option; s.ip_options = ip_option;
} }
if (!s.parts) { if (s.parts != 0) {
free(s.parts); free(s.parts);
s.parts = 0; s.parts = 0;
} }

View file

@ -117,7 +117,7 @@ void mem_delete(struct mphdr *hdr, int pos)
void mem_destroy(struct mphdr *hdr) 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]; struct elem *e = hdr->values[i];
if (!e) { if (!e) {
continue; continue;
@ -125,4 +125,6 @@ void mem_destroy(struct mphdr *hdr)
free(e); free(e);
hdr->values[i] = 0; hdr->values[i] = 0;
} }
memset(hdr, 0, sizeof(*hdr));
free(hdr);
} }