From: nishi Date: Tue, 30 Apr 2024 02:29:17 +0000 (+0000) Subject: fix segfault X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=95bfac7d61b0ee712de9659286a79342c373d0d4;p=serenade.git fix segfault git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@87 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- diff --git a/Serenade/interpreter.c b/Serenade/interpreter.c index ee36afc..e4b3f30 100644 --- a/Serenade/interpreter.c +++ b/Serenade/interpreter.c @@ -181,10 +181,14 @@ struct sn_interpreter* sn_create_interpreter(void) { void sn_interpreter_free(struct sn_interpreter* sn) { int i; for(i = 0; sn->variables[i] != NULL; i++) { - free(sn->variables[i]->key); - if(sn->variables[i]->value != NULL) sn_generic_free(sn, sn->variables[i]->value); - free(sn->variables[i]); - sn->variables[i]->value = NULL; + if(sn->variables[i] != NULL){ + free(sn->variables[i]->key); + if(sn->variables[i]->value != NULL) sn_generic_free(sn, sn->variables[i]->value); + if(sn->variables[i] != NULL){ + sn->variables[i]->value = NULL; + free(sn->variables[i]); + } + } } free(sn->variables); for(i = 0; sn->generics[i] != NULL; i++) { diff --git a/Serenade/parser.c b/Serenade/parser.c index 66fbdeb..798c589 100644 --- a/Serenade/parser.c +++ b/Serenade/parser.c @@ -289,6 +289,7 @@ void sn_generic_free(struct sn_interpreter* sn, struct sn_generic* g) { kvs = malloc(sizeof(struct sn_interpreter_kv*) * (count + 1)); count = 0; for(j = 0; oldkvs[j] != NULL; j++){ + if(oldkvs[j] == (void*)1) continue; kvs[count] = oldkvs[j]; if(oldkvs[j]->value == g){ kvs[count]->value = NULL;