Skip to content

Commit

Permalink
lib/raster: Fix Resource Leak issue in put_title.c (#4821)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Dec 9, 2024
1 parent 4b9a126 commit 17dfb69
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/raster/put_title.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ int Rast_put_cell_title(const char *name, const char *title)
if (!out) {
fclose(in);
G_warning(_("G_put_title - can't create a temp file"));
G_free(tempfile);
return -1;
}

Expand All @@ -52,12 +53,15 @@ int Rast_put_cell_title(const char *name, const char *title)
if (line < 3) {
G_warning(_("category information for [%s] in [%s] invalid"), name,
mapset);
remove(tempfile);
G_free(tempfile);
return -1;
}

in = fopen(tempfile, "r");
if (!in) {
G_warning(_("G_put_title - can't reopen temp file"));
G_free(tempfile);
return -1;
}

Expand All @@ -66,6 +70,8 @@ int Rast_put_cell_title(const char *name, const char *title)
fclose(in);
G_warning(_("can't write category information for [%s] in [%s]"), name,
mapset);
remove(tempfile);
G_free(tempfile);
return -1;
}

Expand All @@ -75,6 +81,7 @@ int Rast_put_cell_title(const char *name, const char *title)
fclose(in);
fclose(out);
remove(tempfile);
G_free(tempfile);

return 1;
}

0 comments on commit 17dfb69

Please sign in to comment.