[esnacc-dev] [TODO] memory allocation cleanups

Aaron Conole aconole at bytheb.org
Wed Jul 20 20:42:35 UTC 2016


Anyone able to continue the work on this?  I'll get to it later; while
I'd like it done before cutting branch-1.8, it may not get there.

-Aaron

---

diff --git a/compiler/core/snacc.c b/compiler/core/snacc.c
index 7ec08ab..90feb17 100644
--- a/compiler/core/snacc.c
+++ b/compiler/core/snacc.c
@@ -957,6 +957,140 @@ error:
         tmpLst = tmpLst->next;
         free(tmp);
     }
+
+    FOR_EACH_LIST_ELMT (currMod, allMods) {
+        if (currMod->imports) {
+            ImportModule *it;
+            FOR_EACH_LIST_ELMT(it, currMod->imports) {
+                if (it->importElmts) {
+                    ImportElmt *e;
+                    FOR_EACH_LIST_ELMT(e, it->importElmts) {
+                        free(e);
+                    }
+                }
+                free(it);
+            }
+            free(currMod->imports);
+        }
+
+        if (currMod->typeDefs) {
+            TypeDef *it;
+            FOR_EACH_LIST_ELMT(it, currMod->typeDefs) {
+                if (it->definedName) {
+                    free(it->definedName);
+                }
+                if (it->type) {
+                    if (it->type->tags) {
+                        Tag *t;
+                        FOR_EACH_LIST_ELMT(t, it->type->tags) {
+                            free(t);
+                        }
+                        free(it->type->tags);
+                        it->type->tags = 0;
+                    }
+                    if (it->type->subtypes) {
+                        free(it->type->subtypes);
+                    }
+                    if (it->type->basicType) {
+                        free(it->type->basicType);
+                    }
+                    if (it->type->tableConstraint) {
+                        free(it->type->tableConstraint);
+                    }
+                    if (it->type->defaultVal) {
+                        if (it->type->defaultVal->fieldName) {
+                            free(it->type->defaultVal->fieldName);
+                        }
+                        free(it->type->defaultVal);
+                    }
+                    if (it->type->typeName) {
+                        free(it->type->typeName);
+                    }
+                    free(it->type);
+                }
+                if (it->cTypeDefInfo) {
+                    free(it->cTypeDefInfo);
+                }
+                if (it->cxxTypeDefInfo) {
+                    free(it->cxxTypeDefInfo);
+                }
+                if (it->idlTypeDefInfo) {
+                    free(it->idlTypeDefInfo);
+                }
+                free(it);
+            }
+            free(currMod->typeDefs);
+        }
+
+        if (currMod->valueDefs) {
+            ValueDef *it;
+            FOR_EACH_LIST_ELMT(it, currMod->valueDefs) {
+                if (it->definedName) {
+                    free(it->definedName);
+                }
+                if (it->value) {
+                    free(it->value);
+                }
+                free(it);
+            }
+            free(currMod->valueDefs);
+        }
+
+        if (currMod->objAssignments) {
+            ObjectAssignment *it;
+            FOR_EACH_LIST_ELMT(it, currMod->objAssignments) {
+                free(it);
+            }
+            free(currMod->objAssignments);
+        }
+
+        if (currMod->objSetAssignments) {
+            ObjectSetAssignment *it;
+            FOR_EACH_LIST_ELMT(it, currMod->objSetAssignments) {
+                free(it);
+            }
+            free(currMod->objSetAssignments);
+        };
+
+        if (currMod->modId) {
+            if (currMod->modId->name) {
+                free(currMod->modId->name);
+            }
+            if (currMod->modId->oid) {
+                free(currMod->modId->oid);
+            }
+        }
+
+        if (currMod->namespaceToUse) {
+            free(currMod->namespaceToUse);
+        }
+
+        if (currMod->cHdrFileName) {
+            free(currMod->cHdrFileName);
+        }
+        if (currMod->cSrcFileName) {
+            free(currMod->cSrcFileName);
+        }
+        if (currMod->cxxHdrFileName) {
+            free(currMod->cxxHdrFileName);
+        }
+        if (currMod->cxxSrcFileName) {
+            free(currMod->cxxSrcFileName);
+        }
+        if (currMod->cxxname) {
+            free(currMod->cxxname);
+        }
+#if IDL
+        if (currMod->idlFileName) {
+            free(currMod->idlFileName);
+        }
+
+        if (currMod->idlname) {
+            free(currMod->idlname);
+        }
+#endif
+        free(currMod);
+    }
     free(allMods);
 
     return 0;


More information about the dev mailing list