changeset 408:3da217bd0e48

Memory leak fixes.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 29 Jul 2002 07:50:29 +0000
parents 1c7ed7097a9c
children 0dbf37be0a5a
files decoders/timidity/common.c decoders/timidity/timidity.c
diffstat 2 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/decoders/timidity/common.c	Sun Jul 21 15:18:49 2002 +0000
+++ b/decoders/timidity/common.c	Mon Jul 29 07:50:29 2002 +0000
@@ -111,8 +111,11 @@
 
   plp->path = safe_malloc(strlen(s) + 1);
   if (plp->path == NULL)
+  {
+      free(plp);
       return;
-  
+  }
+
   strcpy(plp->path, s);
   plp->next = pathlist;
   pathlist = plp;
@@ -126,6 +129,7 @@
     while (plp)
     {
 	next = plp->next;
+	free(plp->path);
 	free(plp);
 	plp = next;
     }
--- a/decoders/timidity/timidity.c	Sun Jul 21 15:18:49 2002 +0000
+++ b/decoders/timidity/timidity.c	Mon Jul 29 07:50:29 2002 +0000
@@ -306,7 +306,10 @@
       }
       if (bank->tone[i].name)
 	free(bank->tone[i].name);
+{
+printf("alloc name\n");
       strcpy((bank->tone[i].name=safe_malloc(strlen(w[1])+1)),w[1]);
+}
       bank->tone[i].note=bank->tone[i].amp=bank->tone[i].pan=
       bank->tone[i].strip_loop=bank->tone[i].strip_envelope=
       bank->tone[i].strip_tail=-1;
@@ -551,13 +554,22 @@
 
 void Timidity_Exit(void)
 {
-  int i;
+  int i, j;
 
   for (i = 0; i < 128; i++)
   {
     if (master_tonebank[i])
     {
-      free(master_tonebank[i]->tone);
+      ToneBankElement *e = master_tonebank[i]->tone;
+      if (e != NULL)
+      {
+        for (j = 0; j < 128; j++)
+        {
+          if (e[j].name != NULL)
+            free(e[j].name);
+        }
+        free(e);
+      }
       free(master_tonebank[i]);
     }
     if (master_drumset[i])