Fix Timidity read_config_file() not closing the file when there is an error. stable-1.0
authorRyan C. Gordon <icculus@icculus.org>
Wed, 15 Jun 2011 16:04:05 -0400
branchstable-1.0
changeset 591 f3fd207c0eea
parent 586 62f763761507
child 592 f31f9ceddec9
Fix Timidity read_config_file() not closing the file when there is an error.

Fixes Bugzilla #1230.

Thanks to Ozkan Sezer for the patch!
(transplanted from 65059e40a1502934c025c183514f26e6ef04d185)
decoders/timidity/timidity.c
--- a/decoders/timidity/timidity.c	Wed Jun 15 13:39:33 2011 -0400
+++ b/decoders/timidity/timidity.c	Wed Jun 15 16:04:05 2011 -0400
@@ -213,7 +213,7 @@
       if (words < 2)
       {
 	SNDDBG(("%s: line %d: No directory given\n", name, line));
-	return -2;
+	goto fail;
       }
       for (i=1; i<words; i++)
 	add_to_pathlist(w[i]);
@@ -223,7 +223,7 @@
       if (words < 2)
       {
 	SNDDBG(("%s: line %d: No file name given\n", name, line));
-	return -2;
+	goto fail;
       }
       for (i=1; i<words; i++)
       {
@@ -238,7 +238,7 @@
       {
 	SNDDBG(("%s: line %d: Must specify exactly one patch name\n",
 		name, line));
-	return -2;
+	goto fail;
       }
       strncpy(def_instr_name, w[1], 255);
       def_instr_name[255]='\0';
@@ -248,14 +248,14 @@
       if (words < 2)
       {
 	SNDDBG(("%s: line %d: No drum set number given\n", name, line));
-	return -2;
+	goto fail;
       }
       i=atoi(w[1]);
       if (i<0 || i>127)
       {
 	SNDDBG(("%s: line %d: Drum set must be between 0 and 127\n",
 		name, line));
-	return -2;
+	goto fail;
       }
       if (!master_drumset[i])
       {
@@ -271,14 +271,14 @@
       if (words < 2)
       {
 	SNDDBG(("%s: line %d: No bank number given\n", name, line));
-	return -2;
+	goto fail;
       }
       i=atoi(w[1]);
       if (i<0 || i>127)
       {
 	SNDDBG(("%s: line %d: Tone bank must be between 0 and 127\n",
 		name, line));
-	return -2;
+	goto fail;
       }
       if (!master_tonebank[i])
       {
@@ -294,20 +294,20 @@
       if ((words < 2) || (*w[0] < '0' || *w[0] > '9'))
       {
 	SNDDBG(("%s: line %d: syntax error\n", name, line));
-	return -2;
+	goto fail;
       }
       i=atoi(w[0]);
       if (i<0 || i>127)
       {
 	SNDDBG(("%s: line %d: Program must be between 0 and 127\n",
 		name, line));
-	return -2;
+	goto fail;
       }
       if (!bank)
       {
 	SNDDBG(("%s: line %d: Must specify tone bank or drum set before assignment\n",
 		name, line));
-	return -2;
+	goto fail;
       }
       if (bank->tone[i].name)
 	free(bank->tone[i].name);
@@ -321,7 +321,7 @@
 	if (!(cp=strchr(w[j], '=')))
 	{
 	  SNDDBG(("%s: line %d: bad patch option %s\n", name, line, w[j]));
-	  return -2;
+	  goto fail;
 	}
 	*cp++=0;
 	if (!strcmp(w[j], "amp"))
@@ -331,7 +331,7 @@
 	  {
 	    SNDDBG(("%s: line %d: amplification must be between 0 and %d\n",
 		    name, line, MAX_AMPLIFICATION));
-	    return -2;
+	    goto fail;
 	  }
 	  bank->tone[i].amp=k;
 	}
@@ -342,7 +342,7 @@
 	  {
 	    SNDDBG(("%s: line %d: note must be between 0 and 127\n",
 		    name, line));
-	    return -2;
+	    goto fail;
 	  }
 	  bank->tone[i].note=k;
 	}
@@ -360,7 +360,7 @@
 	  {
 	    SNDDBG(("%s: line %d: panning must be left, right, center, or between -100 and 100\n",
 		    name, line));
-	    return -2;
+	    goto fail;
 	  }
 	  bank->tone[i].pan=k;
 	}
@@ -373,7 +373,7 @@
 	  else
 	  {
 	    SNDDBG(("%s: line %d: keep must be env or loop\n", name, line));
-	    return -2;
+	    goto fail;
 	  }
 	}
 	else if (!strcmp(w[j], "strip"))
@@ -388,19 +388,22 @@
 	  {
 	    SNDDBG(("%s: line %d: strip must be env, loop, or tail\n",
 		    name, line));
-	    return -2;
+	    goto fail;
 	  }
 	}
 	else
 	{
 	  SNDDBG(("%s: line %d: bad patch option %s\n", name, line, w[j]));
-	  return -2;
+	  goto fail;
 	}
       }
     }
   }
   SDL_RWclose(rw);
   return 0;
+fail:
+  SDL_RWclose(rw);
+  return -2;
 }
 
 int Timidity_Init_NoConfig()