compiler/libec: (#501, #503) Fixed various memory leaks
authorJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 01:24:00 +0000 (21:24 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 19 May 2014 01:24:00 +0000 (21:24 -0400)
compiler/bootstrap/libec/bootstrap/ast.c
compiler/bootstrap/libec/bootstrap/pass1.c
compiler/bootstrap/libec/bootstrap/pass2.c
compiler/libec/src/ast.ec
compiler/libec/src/pass1.ec
compiler/libec/src/pass2.ec

index 9349097..878d90c 100644 (file)
@@ -1590,6 +1590,7 @@ struct Expression * MkExpIntlString(char * string, char * context)
 if(inCompiler)
 {
 struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
+char * s;
 
 if(inCompiler)
 {
@@ -1643,7 +1644,9 @@ struct __ecereNameSpace__ecere__com__Instance * __internal_ClassInst = list;
 __internal_ClassInst ? __internal_ClassInst->_vTbl : __ecereClass___ecereNameSpace__ecere__com__List->_vTbl;
 })[__ecereVMethodID___ecereNameSpace__ecere__com__Container_Add])(list, (&yylloc));
 }
-ListAdd(list, MkExpString(QMkString(i18nModuleName ? i18nModuleName : "")));
+s = QMkString(i18nModuleName ? i18nModuleName : "");
+ListAdd(list, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
 ListAdd(list, MkExpString(string));
 if(context)
 {
index e291176..e147267 100644 (file)
@@ -2308,8 +2308,6 @@ decl->symbol->idCode = symbol->idCode;
 }
 propWatch->compound = (((void *)0));
 __ecereMethod___ecereNameSpace__ecere__sys__OldList_Insert(definitions, (((void *)0)), MkClassDefFunction(func));
-stmt->type = 3;
-stmt->expressions = MkList();
 for(propID = (*propWatch->properties).first; propID; propID = propID->next)
 {
 struct __ecereNameSpace__ecere__com__Property * prop = __ecereNameSpace__ecere__com__eClass_FindProperty(regClass, propID->string, privateModule);
@@ -2319,7 +2317,12 @@ if(prop)
 struct __ecereNameSpace__ecere__sys__OldList * args = MkList();
 
 ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
-ListAdd(args, MkExpString(QMkString(propID->string)));
+{
+char * s = QMkString(propID->string);
+
+ListAdd(args, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
+}
 ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
 ListAdd(stmt->expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
 }
@@ -2804,7 +2807,12 @@ def->propertyWatch = (((void *)0));
 }
 else if(def->type == 5)
 {
-stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=', MkExpString(QMkString(def->designer))))), (((void *)0)));
+{
+char * s = QMkString(def->designer);
+
+stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=', MkExpString(s)))), (((void *)0)));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
+}
 ListAdd(registerModuleBody->compound.statements, stmt);
 }
 else if(def->type == 6)
@@ -2821,8 +2829,11 @@ regClass->fixed = 0x1;
 }
 else if(def->type == 8)
 {
-stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=', MkExpString(QMkString(def->defaultProperty->string))))), (((void *)0)));
+char * s = QMkString(def->defaultProperty->string);
+
+stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=', MkExpString(s)))), (((void *)0)));
 ListAdd(registerModuleBody->compound.statements, stmt);
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
 }
 else if(def->type == 11)
 {
@@ -3072,19 +3083,24 @@ while(__ecereMethod___ecereNameSpace__ecere__com__Iterator_Next(&v))
 struct __ecereNameSpace__ecere__sys__OldList * findClassArgs = MkList();
 struct __ecereNameSpace__ecere__sys__OldList * args = MkList();
 struct Statement * compoundStmt;
+char * s;
 
 ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
-ListAdd(findClassArgs, MkExpString(QMkString(__extension__ ({
+s = QMkString(__extension__ ({
 char * __ecTemp1 = (((struct __ecereNameSpace__ecere__com__Instance *)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(&v)));
 
 ((struct ClassPropertyValue *)(__ecTemp1 + __ecereClass_ClassPropertyValue->offset));
-})->regClass->name)));
+})->regClass->name);
+ListAdd(findClassArgs, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
 ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
-ListAdd(args, MkExpString(QMkString(__extension__ ({
+s = QMkString(__extension__ ({
 char * __ecTemp1 = (((struct __ecereNameSpace__ecere__com__Instance *)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(&v)));
 
 ((struct ClassPropertyValue *)(__ecTemp1 + __ecereClass_ClassPropertyValue->offset));
-})->id->string)));
+})->id->string);
+ListAdd(args, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
 ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), (((void *)0))), __extension__ ({
 char * __ecTemp1 = (((struct __ecereNameSpace__ecere__com__Instance *)__ecereProp___ecereNameSpace__ecere__com__Iterator_Get_data(&v)));
 
index b168ea6..834a833 100644 (file)
@@ -1097,6 +1097,8 @@ static struct Statement * curCompound;
 
 extern struct Expression * CopyExpression(struct Expression * exp);
 
+extern void FreeExpContents(struct Expression * exp);
+
 extern void FreeExpression(struct Expression * exp);
 
 void __ecereMethod___ecereNameSpace__ecere__sys__OldList_Remove(struct __ecereNameSpace__ecere__sys__OldList * this, void *  item);
@@ -1119,6 +1121,7 @@ struct Expression * exp = *expPtr;
 
 *memberExpPtr = (((void *)0));
 newExp = CopyExpression(exp);
+FreeExpContents(exp);
 *(struct Expression **)((unsigned char *)newExp + ((unsigned char *)memberExpPtr - (unsigned char *)exp)) = memberExp;
 memberExp->member.exp = idExp;
 exp->type = 5;
@@ -1309,6 +1312,8 @@ extern struct Expression * MkExpIdentifier(struct Identifier * id);
 
 extern struct Identifier * MkIdentifier(char *  string);
 
+extern void FreeSpecifier(struct Specifier * spec);
+
 extern char *  __ecereNameSpace__ecere__sys__CopyString(char *  string);
 
 extern void ListAdd(struct __ecereNameSpace__ecere__sys__OldList * list, void *  item);
@@ -1381,12 +1386,10 @@ unsigned int constant;
 
 extern struct __ecereNameSpace__ecere__com__ClassProperty * __ecereNameSpace__ecere__com__eClass_FindClassProperty(struct __ecereNameSpace__ecere__com__Class * _class, char *  name);
 
-extern void FreeExpContents(struct Expression * exp);
+extern char *  QMkString(char *  source);
 
 extern struct Expression * MkExpString(char *  string);
 
-extern char *  QMkString(char *  source);
-
 extern struct Specifier * MkSpecifier(int specifier);
 
 extern void FreeIdentifier(struct Identifier * id);
@@ -1457,6 +1460,8 @@ extern struct Context * SetupTemplatesContext(struct __ecereNameSpace__ecere__co
 
 extern void FinishTemplatesContext(struct Context * context);
 
+extern void FreeTypeName(struct TypeName * typeName);
+
 extern struct Specifier * MkStructOrUnion(int type, struct Identifier * id, struct __ecereNameSpace__ecere__sys__OldList * definitions);
 
 extern struct Type * ProcessTypeString(char *  string, unsigned int staticMethod);
@@ -1465,8 +1470,6 @@ extern void PrintTypeNoConst(struct Type * type, char *  string, unsigned int pr
 
 extern int ComputeTypeSize(struct Type * type);
 
-extern void FreeTypeName(struct TypeName * typeName);
-
 extern struct Type * ProcessType(struct __ecereNameSpace__ecere__sys__OldList * specs, struct Declarator * decl);
 
 extern unsigned int internalValueCounter;
@@ -1477,8 +1480,6 @@ extern struct Type * ProcessTemplateParameterType(struct TemplateParameter * par
 
 extern void DeclareStruct(char *  name, unsigned int skipNoHead);
 
-extern void FreeSpecifier(struct Specifier * spec);
-
 static void ProcessStatement(struct Statement * stmt);
 
 extern void FreeList(struct __ecereNameSpace__ecere__sys__OldList * list, void (*  FreeFunction)(void * ));
@@ -1563,6 +1564,7 @@ FullClassNameCat(name, method->_class->fullName, 0x0);
 strcat(name, "_");
 strcat(name, method->name);
 (__ecereNameSpace__ecere__com__eSystem_Delete(exp->identifier->string), exp->identifier->string = 0);
+FreeSpecifier(exp->identifier->_class);
 exp->identifier->_class = (((void *)0));
 exp->identifier->string = __ecereNameSpace__ecere__sys__CopyString(name);
 DeclareMethod(method, name);
@@ -1927,7 +1929,12 @@ exp->type = 7;
 exp->call.exp = MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty"));
 exp->call.arguments = MkList();
 ListAdd(exp->call.arguments, classExp);
-ListAdd(exp->call.arguments, MkExpString(QMkString(id->string)));
+{
+char * s = QMkString(id->string);
+
+ListAdd(exp->call.arguments, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
+}
 ListAdd(exp->call.arguments, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), (((void *)0))), value));
 FreeIdentifier(id);
 ProcessExpression(exp);
@@ -2160,6 +2167,8 @@ struct Expression * object = exp->op.exp2;
 
 exp->op.exp2 = (((void *)0));
 FreeExpContents(exp);
+FreeType(exp->expType);
+FreeType(exp->destType);
 exp->expType = (((void *)0));
 exp->destType = (((void *)0));
 exp->op.op = INC_OP;
@@ -2580,7 +2589,10 @@ struct TypeName * firstParam = ((struct TypeName *)(*funcDecl->function.paramete
 struct Specifier * firstSpec = firstParam ? (*firstParam->qualifiers).first : (((void *)0));
 
 if(firstParam && firstSpec && firstSpec->type == 0 && firstSpec->specifier == VOID && !firstParam->declarator)
+{
 __ecereMethod___ecereNameSpace__ecere__sys__OldList_Remove((&*funcDecl->function.parameters), (*funcDecl->function.parameters).first);
+FreeTypeName(firstParam);
+}
 }
 if(method->dataType->thisClass && !strcmp(method->dataType->thisClass->string, "class"))
 {
@@ -2755,6 +2767,8 @@ if(typedObject && !memberExp->member.exp->expType->classObjectType)
 {
 struct Type * destType = (destType = __ecereNameSpace__ecere__com__eInstance_New(__ecereClass_Type), destType->refCount = 1, destType->kind = 8, destType->classObjectType = 3, destType);
 
+FreeType((parentExp ? parentExp : newExp)->expType);
+FreeType((parentExp ? parentExp : newExp)->destType);
 (parentExp ? parentExp : newExp)->expType = checkedExp->expType;
 (parentExp ? parentExp : newExp)->destType = destType;
 if(checkedExp->expType)
@@ -3299,7 +3313,12 @@ exp->type = 7;
 exp->call.exp = MkExpIdentifier(MkIdentifier("ecere::com::eClass_GetProperty"));
 exp->call.arguments = MkList();
 ListAdd(exp->call.arguments, classExp);
-ListAdd(exp->call.arguments, MkExpString(QMkString(id->string)));
+{
+char * s = QMkString(id->string);
+
+ListAdd(exp->call.arguments, MkExpString(s));
+(__ecereNameSpace__ecere__com__eSystem_Delete(s), s = 0);
+}
 FreeIdentifier(id);
 ProcessExpression(exp);
 return ;
@@ -3332,6 +3351,7 @@ MangleClassName(className);
 if(!_class->symbol)
 _class->symbol = FindClass(_class->fullName);
 DeclareClass(_class->symbol, className);
+FreeExpression(exp->member.exp);
 exp->index.exp = MkExpPointer(MkExpIdentifier(MkIdentifier(className)), MkIdentifier("_vTbl"));
 }
 else
index b2c9036..38ccd41 100644 (file)
@@ -280,6 +280,7 @@ Expression MkExpIntlString(char * string, char * context)
    if(inCompiler)
    {
       OldList * list = MkList();
+      String s;
       if(inCompiler)
       {
          ContextStringPair pair { };
@@ -303,7 +304,9 @@ Expression MkExpIntlString(char * string, char * context)
          list.Add(yylloc);
       }
       //ListAdd(list, QMkExpId("__thisModule"));
-      ListAdd(list, MkExpString(QMkString(i18nModuleName ? i18nModuleName : "")));
+      s = QMkString(i18nModuleName ? i18nModuleName : "");
+      ListAdd(list, MkExpString(s));
+      delete s;
       ListAdd(list, MkExpString(string));
       if(context)
       {
index 456a1d9..4d5bc7a 100644 (file)
@@ -1051,9 +1051,6 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                   propWatch.compound = null;
                   definitions.Insert(null, MkClassDefFunction(func));
 
-                  stmt.type = expressionStmt;
-                  stmt.expressions = MkList();
-
                   for(propID = propWatch.properties->first; propID; propID = propID.next)
                   {
                      Property prop = eClass_FindProperty(regClass, propID.string, privateModule);
@@ -1062,7 +1059,11 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                         // eProperty_SelfWatch(_class, name, callback);
                         OldList * args = MkList();
                         ListAdd(args, MkExpIdentifier(MkIdentifier("class")));
-                        ListAdd(args, MkExpString(QMkString(propID.string)));
+                        {
+                           char * s = QMkString(propID.string);
+                           ListAdd(args, MkExpString(s));
+                           delete s;
+                        }
                         ListAdd(args, MkExpIdentifier(MkIdentifier(watcherName)));
 
                         ListAdd(stmt.expressions, MkExpCall(MkExpIdentifier(MkIdentifier("eProperty_SelfWatch")), args));
@@ -1681,9 +1682,13 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                   DeclareClass(FindClass(def.designer), className);
                   */
 
-                  stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
-                     MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
-                        MkExpString(QMkString(def.designer))))), null);
+                  {
+                     char * s = QMkString(def.designer);
+                     stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
+                        MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("designerClass")), '=',
+                           MkExpString(s)))), null);
+                     delete s;
+                  }
                   ListAdd(registerModuleBody.compound.statements, stmt);
                }
                else if(def.type == classNoExpansionClassDef)
@@ -1704,10 +1709,12 @@ static void ProcessClass(ClassType classType, OldList definitions, Symbol symbol
                }
                else if(def.type == designerDefaultPropertyClassDef)
                {
+                  char * s = QMkString(def.defaultProperty.string);
                   stmt = MkIfStmt(MkListOne(MkExpIdentifier(MkIdentifier("class"))), MkExpressionStmt(MkListOne(
                      MkExpOp(MkExpMember(MkExpIdentifier(MkIdentifier("class")), MkIdentifier("defaultProperty")), '=',
-                        MkExpString(QMkString(def.defaultProperty.string))))), null);
+                        MkExpString(s)))), null);
                   ListAdd(registerModuleBody.compound.statements, stmt);
+                  delete s;
                }
                else if(def.type == classPropertyValueClassDef)
                {
@@ -1950,12 +1957,17 @@ public void ProcessClassDefinitions()
          OldList * findClassArgs = MkList();
          OldList * args = MkList();
          Statement compoundStmt;
+         String s;
 
          ListAdd(findClassArgs, MkExpIdentifier(MkIdentifier("module")));
-         ListAdd(findClassArgs, MkExpString(QMkString(v.regClass.name)));
+         s = QMkString(v.regClass.name);
+         ListAdd(findClassArgs, MkExpString(s));
+         delete s;
 
          ListAdd(args, MkExpIdentifier(MkIdentifier("_class")));
-         ListAdd(args, MkExpString(QMkString(v.id.string)));
+         s = QMkString(v.id.string);
+         ListAdd(args, MkExpString(s));
+         delete s;
          ListAdd(args, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), v.exp));
          compoundStmt = MkCompoundStmt(MkListOne(MkDeclaration(MkListOne(MkSpecifierName("ecere::com::Class")),
                        MkListOne(MkInitDeclarator(MkDeclaratorIdentifier(MkIdentifier("_class")),
index 5e08824..938e562 100644 (file)
@@ -26,6 +26,8 @@ static void _FixRefExp(Expression * expPtr, Expression * memberExpPtr)
 
          *memberExpPtr = null;
          newExp = CopyExpression(exp);
+         FreeExpContents(exp);
+
          *(Expression *)((byte *)newExp + (uint)((byte *)memberExpPtr - (byte *)exp)) = memberExp;
 
          memberExp.member.exp = idExp;
@@ -271,6 +273,7 @@ static void ProcessExpression(Expression exp)
                strcat(name, method.name);
 
                delete exp.identifier.string;
+               FreeSpecifier(exp.identifier._class);
 
                exp.identifier._class = null;
                exp.identifier.string = CopyString(name);
@@ -708,7 +711,11 @@ static void ProcessExpression(Expression exp)
                               exp.call.exp = MkExpIdentifier(MkIdentifier("ecere::com::eClass_SetProperty"));
                               exp.call.arguments = MkList();
                               ListAdd(exp.call.arguments, classExp);
-                              ListAdd(exp.call.arguments, MkExpString(QMkString(id.string)));
+                              {
+                                 char * s = QMkString(id.string);
+                                 ListAdd(exp.call.arguments, MkExpString(s));
+                                 delete s;
+                              }
                               ListAdd(exp.call.arguments, MkExpCast(MkTypeName(MkListOne(MkSpecifier(INT64)), null), value));
 
                               FreeIdentifier(id);
@@ -954,6 +961,8 @@ static void ProcessExpression(Expression exp)
             Expression object = exp.op.exp2;
             exp.op.exp2 = null;
             FreeExpContents(exp);
+            FreeType(exp.expType);
+            FreeType(exp.destType);
             exp.expType = null;
             exp.destType = null;
             exp.op.op = INC_OP;
@@ -1639,7 +1648,10 @@ static void ProcessExpression(Expression exp)
                      Specifier firstSpec = firstParam ? firstParam.qualifiers->first : null;
 
                      if(firstParam && firstSpec && firstSpec.type == baseSpecifier && firstSpec.specifier == VOID && !firstParam.declarator)
+                     {
                         funcDecl.function.parameters->Remove(funcDecl.function.parameters->first);
+                        FreeTypeName(firstParam);
+                     }
                   }
 
                   if(method.dataType.thisClass && !strcmp(method.dataType.thisClass.string, "class"))
@@ -1892,6 +1904,8 @@ static void ProcessExpression(Expression exp)
                            if(typedObject && !memberExp.member.exp.expType.classObjectType)
                            {
                               Type destType { refCount = 1, kind = classType, classObjectType = ClassObjectType::anyObject };
+                              FreeType((parentExp ? parentExp : newExp).expType);
+                              FreeType((parentExp ? parentExp : newExp).destType);
                               (parentExp ? parentExp : newExp).expType = checkedExp.expType;
                               (parentExp ? parentExp : newExp).destType = destType;
                               if(checkedExp.expType) checkedExp.expType.refCount++;
@@ -2560,7 +2574,11 @@ static void ProcessExpression(Expression exp)
                      exp.call.exp = MkExpIdentifier(MkIdentifier("ecere::com::eClass_GetProperty"));
                      exp.call.arguments = MkList();
                      ListAdd(exp.call.arguments, classExp);
-                     ListAdd(exp.call.arguments, MkExpString(QMkString(id.string)));
+                     {
+                        char * s = QMkString(id.string);
+                        ListAdd(exp.call.arguments, MkExpString(s));
+                        delete s;
+                     }
                      FreeIdentifier(id);
 
                      ProcessExpression(exp);
@@ -2600,9 +2618,9 @@ static void ProcessExpression(Expression exp)
                         if(!_class.symbol)
                            _class.symbol = FindClass(_class.fullName);
                         DeclareClass(_class.symbol, className);
-                        exp.index.exp = MkExpPointer(MkExpIdentifier(MkIdentifier(className)), MkIdentifier("_vTbl"));
 
-                        // WHAT HAPPENS TO exp.member.exp ?
+                        FreeExpression(exp.member.exp);
+                        exp.index.exp = MkExpPointer(MkExpIdentifier(MkIdentifier(className)), MkIdentifier("_vTbl"));
                      }
                      else
                      {