You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/11/24 17:56:57 UTC

lucy-clownfish git commit: Fix segfault if CFCClass_create dies early

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master d0296b14a -> 27177dfc3


Fix segfault if CFCClass_create dies early

If the CFCClass destructor is called early because of an error during
CFCClass_create, fields like self->children aren't initialized yet
resulting in a segfault.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/27177dfc
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/27177dfc
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/27177dfc

Branch: refs/heads/master
Commit: 27177dfc39227ec4e9fc7891bdee6e4a33bdef1b
Parents: d0296b1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Nov 24 17:52:52 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Nov 24 17:55:52 2014 +0100

----------------------------------------------------------------------
 compiler/src/CFCClass.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/27177dfc/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCClass.c b/compiler/src/CFCClass.c
index 59ec8c3..a64b9ae 100644
--- a/compiler/src/CFCClass.c
+++ b/compiler/src/CFCClass.c
@@ -208,31 +208,26 @@ CFCClass_do_create(CFCClass *self, struct CFCParcel *parcel,
     return self;
 }
 
+static void
+S_free_cfcbase_array(CFCBase **array) {
+    if (array != NULL) {
+        for (size_t i = 0; array[i] != NULL; i++) {
+            CFCBase_decref(array[i]);
+        }
+        FREEMEM(array);
+    }
+}
+
 void
 CFCClass_destroy(CFCClass *self) {
     CFCBase_decref((CFCBase*)self->docucomment);
     CFCBase_decref((CFCBase*)self->parent);
-    for (size_t i = 0; self->children[i] != NULL; i++) {
-        CFCBase_decref((CFCBase*)self->children[i]);
-    }
-    for (size_t i = 0; self->functions[i] != NULL; i++) {
-        CFCBase_decref((CFCBase*)self->functions[i]);
-    }
-    for (size_t i = 0; self->methods[i] != NULL; i++) {
-        CFCBase_decref((CFCBase*)self->methods[i]);
-    }
-    for (size_t i = 0; self->member_vars[i] != NULL; i++) {
-        CFCBase_decref((CFCBase*)self->member_vars[i]);
-    }
-    for (size_t i = 0; self->inert_vars[i] != NULL; i++) {
-        CFCBase_decref((CFCBase*)self->inert_vars[i]);
-    }
     CFCBase_decref((CFCBase*)self->file_spec);
-    FREEMEM(self->children);
-    FREEMEM(self->functions);
-    FREEMEM(self->methods);
-    FREEMEM(self->member_vars);
-    FREEMEM(self->inert_vars);
+    S_free_cfcbase_array((CFCBase**)self->children);
+    S_free_cfcbase_array((CFCBase**)self->functions);
+    S_free_cfcbase_array((CFCBase**)self->methods);
+    S_free_cfcbase_array((CFCBase**)self->member_vars);
+    S_free_cfcbase_array((CFCBase**)self->inert_vars);
     FREEMEM(self->parent_class_name);
     FREEMEM(self->struct_sym);
     FREEMEM(self->ivars_struct);