Skip to content

Commit

Permalink
fix resource leak in opl2iso
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Aug 17, 2021
1 parent 5030ae7 commit da81967
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pc/opl2iso/src/opl2iso.c
Expand Up @@ -116,14 +116,15 @@ int listGames(void)
//-----------------------------------------------------------------------
int findGame(const char *gameid, cfg_t *item)
{
// open ul.cfg
FILE *ul = fopen("ul.cfg", "rb");
FILE *ul;

if (!item) {
printf("Invalid target record (internal error)!\n");
return EXIT_FAILURE;
}

// open ul.cfg
ul = fopen("ul.cfg", "rb");
if (ul == NULL) {
printf("No ul.cfg in the current directory!\n");
return EXIT_FAILURE;
Expand All @@ -146,16 +147,22 @@ int findGame(const char *gameid, cfg_t *item)
fread(item->pad, 1, sizeof(item->pad), ul);

// in the ul.????_???.?? form?
if (strncmp(item->image, gameid, 15) == 0)
if (strncmp(item->image, gameid, 15) == 0) {
fclose(ul);
return 1;
}

// in the ????_???.?? form?
if (strncmp(&item->image[3], gameid, 12) == 0)
if (strncmp(&item->image[3], gameid, 12) == 0) {
fclose(ul);
return 1;
}

// game name itself?
if (strncmp(item->name, gameid, 32) == 0)
if (strncmp(item->name, gameid, 32) == 0) {
fclose(ul);
return 1;
}

// in the ul.????????.????_???.??.?? form? (Drag-Dropped part-file name)
char *temp;
Expand All @@ -171,8 +178,10 @@ int findGame(const char *gameid, cfg_t *item)
if ((strlen(temp) >= 23) // Minimum part file name length is really 26
&& (strncmp("ul.", temp, 3) == 0) //"ul." at start
&& (strncmp(&item->image[2], &(temp[11]), 12) == 0) //.game_ID after CRC
)
) {
fclose(ul);
return 1;
}
}

fclose(ul);
Expand Down Expand Up @@ -253,12 +262,14 @@ int exportGame(const char *gameid)
if (read != fwrite(block, 1, read, fdest)) {
printf("Could not write to destination file '%s' (Insufficient disk space?). Resulting file will be invalid\n", rname);
fclose(fdest);
fclose(fsrc);
return EXIT_FAILURE;
}
}
}

fclose(fdest);
fclose(fsrc);

printf("* All parts processed...\n");

Expand Down

0 comments on commit da81967

Please sign in to comment.