From: uz Date: Mon, 1 Aug 2011 20:49:59 +0000 (+0000) Subject: Fixed a rather large memory leak. X-Git-Tag: V2.13.3~360 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=67692e51f1025654a7f8c7cd7ae6457023bd5ad1;p=cc65 Fixed a rather large memory leak. git-svn-id: svn://svn.cc65.org/cc65/trunk@5102 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/lineinfo.c b/src/ld65/lineinfo.c index 243556363..2ed4f7a33 100644 --- a/src/ld65/lineinfo.c +++ b/src/ld65/lineinfo.c @@ -72,6 +72,15 @@ static CodeRange* NewCodeRange (Segment* Seg, unsigned long Offs, unsigned long +static void FreeCodeRange (CodeRange* R) +/* Free a CodeRange structure */ +{ + /* Just free the memory */ + xfree (R); +} + + + static LineInfo* NewLineInfo (void) /* Create and return a new LineInfo struct with mostly empty fields */ { @@ -93,6 +102,30 @@ static LineInfo* NewLineInfo (void) +void FreeLineInfo (LineInfo* LI) +/* Free a LineInfo structure. This function will not handle a non empty + * Fragments collection, it can only be used to free incomplete line infos. + */ +{ + unsigned I; + + /* Check, check, ... */ + PRECONDITION (CollCount (&LI->Fragments) == 0); + + /* Free all the code ranges */ + for (I = 0; I < CollCount (&LI->CodeRanges); ++I) { + FreeCodeRange (CollAtUnchecked (&LI->CodeRanges, I)); + } + + /* Free the collections */ + DoneCollection (&LI->CodeRanges); + + /* Free the structure itself */ + xfree (LI); +} + + + LineInfo* GenLineInfo (const FilePos* Pos) /* Generate a new (internally used) line info with the given information */ { @@ -245,4 +278,4 @@ void RelocLineInfo (Segment* S) - + diff --git a/src/ld65/lineinfo.h b/src/ld65/lineinfo.h index 569ed7975..0c92423fc 100644 --- a/src/ld65/lineinfo.h +++ b/src/ld65/lineinfo.h @@ -97,11 +97,16 @@ struct LineInfo { LineInfo* GenLineInfo (const FilePos* Pos); -/* Generate a new (internally used) line info with the given information */ +/* Generate a new (internally used) line info with the given information */ LineInfo* ReadLineInfo (FILE* F, struct ObjData* O); /* Read a line info from a file and return it */ +void FreeLineInfo (LineInfo* LI); +/* Free a LineInfo structure. This function will not handle a non empty + * Fragments collection, it can only be used to free incomplete line infos. + */ + void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos); /* Read a list of line infos stored as a list of indices in the object file, * make real line infos from them and place them into the passed collection. diff --git a/src/ld65/objdata.c b/src/ld65/objdata.c index 9d71a3ab9..fe6850513 100644 --- a/src/ld65/objdata.c +++ b/src/ld65/objdata.c @@ -105,14 +105,17 @@ void FreeObjData (ObjData* O) /* Unused ObjData do only have the string pool, Exports and Imports. */ for (I = 0; I < CollCount (&O->Exports); ++I) { - FreeExport (CollAt (&O->Exports, I)); + FreeExport (CollAtUnchecked (&O->Exports, I)); } DoneCollection (&O->Exports); for (I = 0; I < CollCount (&O->Imports); ++I) { - FreeImport (CollAt (&O->Imports, I)); + FreeImport (CollAtUnchecked (&O->Imports, I)); } DoneCollection (&O->Imports); DoneCollection (&O->DbgSyms); + for (I = 0; I < CollCount (&O->LineInfos); ++I) { + FreeLineInfo (CollAtUnchecked (&O->LineInfos, I)); + } DoneCollection (&O->LineInfos); xfree (O->Strings); DoneCollection (&O->Assertions);