]> Nishi Git Mirror - serenade.git/commitdiff
fix segfault
authornishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 30 Apr 2024 02:29:17 +0000 (02:29 +0000)
committernishi <nishi@0f02c867-ac3d-714e-8a88-971ba1f6efcf>
Tue, 30 Apr 2024 02:29:17 +0000 (02:29 +0000)
git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@87 0f02c867-ac3d-714e-8a88-971ba1f6efcf

Serenade/interpreter.c
Serenade/parser.c

index ee36afc279c06b46ed34027e64948cc8f0218d29..e4b3f30a7b5897e870670e1ad23a2a6b1d0d50d3 100644 (file)
@@ -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++) {
index 66fbdebfb06c1acfe632ad4c25a7af8c95f9e202..798c5892122c3912e581e1a3d0d21707fabefa9c 100644 (file)
@@ -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;