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) {
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;
}

View file

@ -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);
}