Skip to content

Commit

Permalink
Fix Timidity read_config_file() not closing the file when there is an…
Browse files Browse the repository at this point in the history
… error.

Fixes Bugzilla #1230.

Thanks to Ozkan Sezer for the patch!
(transplanted from 65059e40a1502934c025c183514f26e6ef04d185)
  • Loading branch information
icculus committed Jun 15, 2011
1 parent 0e51976 commit 9f7563f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions decoders/timidity/timidity.c
Expand Up @@ -213,7 +213,7 @@ static int read_config_file(char *name)
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]);
Expand All @@ -223,7 +223,7 @@ static int read_config_file(char *name)
if (words < 2)
{
SNDDBG(("%s: line %d: No file name given\n", name, line));
return -2;
goto fail;
}
for (i=1; i<words; i++)
{
Expand All @@ -238,7 +238,7 @@ static int read_config_file(char *name)
{
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';
Expand All @@ -248,14 +248,14 @@ static int read_config_file(char *name)
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])
{
Expand All @@ -271,14 +271,14 @@ static int read_config_file(char *name)
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])
{
Expand All @@ -294,20 +294,20 @@ static int read_config_file(char *name)
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);
Expand All @@ -321,7 +321,7 @@ static int read_config_file(char *name)
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"))
Expand All @@ -331,7 +331,7 @@ static int read_config_file(char *name)
{
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;
}
Expand All @@ -342,7 +342,7 @@ static int read_config_file(char *name)
{
SNDDBG(("%s: line %d: note must be between 0 and 127\n",
name, line));
return -2;
goto fail;
}
bank->tone[i].note=k;
}
Expand All @@ -360,7 +360,7 @@ static int read_config_file(char *name)
{
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;
}
Expand All @@ -373,7 +373,7 @@ static int read_config_file(char *name)
else
{
SNDDBG(("%s: line %d: keep must be env or loop\n", name, line));
return -2;
goto fail;
}
}
else if (!strcmp(w[j], "strip"))
Expand All @@ -388,19 +388,22 @@ static int read_config_file(char *name)
{
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()
Expand Down

0 comments on commit 9f7563f

Please sign in to comment.