]> git.sur5r.net Git - cc65/commitdiff
Removed several memory leaks.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 10 Mar 2012 21:46:09 +0000 (21:46 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 10 Mar 2012 21:46:09 +0000 (21:46 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5595 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/attr.c
src/sp65/attr.h
src/sp65/bitmap.c
src/sp65/main.c
src/sp65/pcx.c

index 2b8c209fda60b28e7d666486f091a288dab72726..8f9b11d74c76a715367066e546907b30c8dc7256 100644 (file)
@@ -87,6 +87,18 @@ Attr* NewAttr (const char* Name, const char* Value)
 
 
 
+void FreeAttr (Attr* A)
+/* Free an attribute structure */
+{
+    /* Allow NULL pointers */
+    if (A) {
+        xfree (A->Name);
+        xfree (A);
+    }
+}
+
+
+
 void DumpAttrColl (const Collection* C)
 /* Dump a collection of attribute/value pairs for debugging */
 {
@@ -240,7 +252,7 @@ void SplitAddAttr (Collection* C, const char* Combined, const char* Name)
 
         /* Release memory */
         SB_Done (&N);
-    }                                 
+    }
 }
 
 
@@ -296,3 +308,19 @@ Collection* ParseAttrList (const char* List, const char** NameList, unsigned Nam
 
 
 
+void FreeAttrList (Collection* C)
+/* Free a list of attributes */  
+{
+    unsigned I;
+
+    /* Walk over the collection and free all attributes */
+    for (I = 0; I < CollCount (C); ++I) {
+        FreeAttr (CollAtUnchecked (C, I));
+    }
+
+    /* Free the collection itself */
+    FreeCollection (C);
+}
+
+
+
index 9379a802094769e8372ffa96d1ab858b75a5f544..d7df963d77ff0b9d2615f110445e663053de41b3 100644 (file)
@@ -75,6 +75,9 @@ struct Attr {
 Attr* NewAttr (const char* Name, const char* Value);
 /* Create a new attribute */
 
+void FreeAttr (Attr* A);
+/* Free an attribute structure */
+
 void DumpAttrColl (const Collection* C);
 /* Dump a collection of attribute/value pairs for debugging */
 
@@ -92,7 +95,7 @@ const Attr* GetAttr (const Collection* C, const char* Name);
 
 const Attr* NeedAttr (const Collection* C, const char* Name, const char* Op);
 /* Search for an attribute with the given name and return it. If the attribute
- * is not found, the function terminates with an error using Op as additional 
+ * is not found, the function terminates with an error using Op as additional
  * context in the error message.
  */
 
@@ -123,6 +126,9 @@ Collection* ParseAttrList (const char* List, const char** NameList, unsigned Nam
  * containing Attr entries.
  */
 
+void FreeAttrList (Collection* C);
+/* Free a list of attributes */
+
 
 
 /* End of attr.h */
index 865eab272e51b89615996978c06a81e8bb7edcc2..b00a01651b65c7aa022814923613d5ebaa21536f 100644 (file)
@@ -81,7 +81,8 @@ void FreeBitmap (Bitmap* B)
 {
     /* Alloc NULL pointers */
     if (B != 0) {
-        /* Free the palette and then the bitmap */
+        /* Free name, palette and then the bitmap */
+        SB_Done (&B->Name);
         xfree (B->Pal);
         xfree(B);
     }
@@ -190,7 +191,7 @@ unsigned GetBitmapColors (const Bitmap* B)
         case bmRGB:
         case bmRGBA:            return (1U << 24);
         default:                Internal ("Unknown bitmap type %u", B->Type);
-    }   
+    }
     /* NOTREACHED */
     return 0;
 }
index c0d912eb03deb7a54510aa188824cf789ddcfb80..a6b63ce2017cf3579b72a6b500ae1bc3af1d63ba 100644 (file)
@@ -156,7 +156,7 @@ static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg)
     SetOutputData (ConvertTo (C, A));
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
 }
 
 
@@ -217,7 +217,7 @@ static void OptRead (const char* Opt attribute ((unused)), const char* Arg)
     B = C = ReadInputFile (A);
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
 }
 
 
@@ -286,7 +286,7 @@ static void OptWrite (const char* Opt attribute ((unused)), const char* Arg)
     WriteOutputFile (D, A);
 
     /* Delete the attribute list */
-    FreeCollection (A);
+    FreeAttrList (A);
 }
 
 
index 53075a1e6186606fd55e39d1ff5be1ef89ace563..7dc9d9c9b46bb1a2443822c8e8a8c89a2ecaea0a 100644 (file)
@@ -437,6 +437,9 @@ Bitmap* ReadPCXFile (const Collection* A)
     /* Close the file */
     fclose (F);
 
+    /* Free memory for the scan line */
+    xfree (L);
+
     /* Free the PCX header */
     FreePCXHeader (P);