Skip to content

Commit

Permalink
Dynamically allocate file name buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
knik committed Mar 4, 2012
1 parent bfab0b0 commit 720f700
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions frontend/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
** $Id: main.c,v 1.87 2012/03/02 15:28:44 knik Exp $
** $Id: main.c,v 1.88 2012/03/04 09:59:02 knik Exp $
**/

#ifdef _WIN32
Expand Down Expand Up @@ -1109,9 +1109,9 @@ int main(int argc, char *argv[])
int mp4file = 0;
int noGapless = 0;
char *fnp;
char aacFileName[255];
char audioFileName[255];
char adtsFileName[255];
char *aacFileName = NULL;
char *audioFileName = NULL;
char *adtsFileName = NULL;
unsigned char header[8];
float length = 0;
FILE *hMP4File;
Expand Down Expand Up @@ -1159,13 +1159,25 @@ int main(int argc, char *argv[])
if (optarg)
{
outfile_set = 1;
audioFileName = (char *) malloc(sizeof(char) * (strlen(optarg) + 1));
if (audioFileName == NULL)
{
faad_fprintf(stderr, "Error allocating memory for audioFileName.\n");
return 1;
}
strcpy(audioFileName, optarg);
}
break;
case 'a':
if (optarg)
{
adts_out = 1;
adtsFileName = (char *) malloc(sizeof(char) * (strlen(optarg) + 1));
if (adtsFileName == NULL)
{
faad_fprintf(stderr, "Error allocating memory for adtsFileName.\n");
return 1;
}
strcpy(adtsFileName, optarg);
}
break;
Expand Down Expand Up @@ -1286,6 +1298,12 @@ int main(int argc, char *argv[])
#endif

/* point to the specified file name */
aacFileName = (char *) malloc(sizeof(char) * (strlen(argv[optind]) + 1));
if (aacFileName == NULL)
{
faad_fprintf(stderr, "Error allocating memory for aacFileName.\n");
return 1;
}
strcpy(aacFileName, argv[optind]);

#ifdef _WIN32
Expand All @@ -1299,6 +1317,12 @@ int main(int argc, char *argv[])
*/
if(!writeToStdio && !outfile_set)
{
audioFileName = (char *) malloc(sizeof(char) * (strlen(aacFileName) + strlen(file_ext[format]) + 1));
if (audioFileName == NULL)
{
faad_fprintf(stderr, "Error allocating memory for audioFileName.\n");
return 1;
}
strcpy(audioFileName, aacFileName);

fnp = (char *)strrchr(audioFileName,'.');
Expand Down Expand Up @@ -1359,6 +1383,11 @@ int main(int argc, char *argv[])
old_format, &length);
}

if (audioFileName != NULL)
free (audioFileName);
if (adtsFileName != NULL)
free (adtsFileName);

if (!result && !infoOnly)
{
#ifdef _WIN32
Expand All @@ -1374,5 +1403,8 @@ int main(int argc, char *argv[])
dec_length, length/dec_length);
}

if (aacFileName != NULL)
free (aacFileName);

return 0;
}

0 comments on commit 720f700

Please sign in to comment.