Skip to content

Commit 17dfb69

Browse files
authored
lib/raster: Fix Resource Leak issue in put_title.c (#4821)
1 parent 4b9a126 commit 17dfb69

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/raster/put_title.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ int Rast_put_cell_title(const char *name, const char *title)
3535
if (!out) {
3636
fclose(in);
3737
G_warning(_("G_put_title - can't create a temp file"));
38+
G_free(tempfile);
3839
return -1;
3940
}
4041

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

5861
in = fopen(tempfile, "r");
5962
if (!in) {
6063
G_warning(_("G_put_title - can't reopen temp file"));
64+
G_free(tempfile);
6165
return -1;
6266
}
6367

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

@@ -75,6 +81,7 @@ int Rast_put_cell_title(const char *name, const char *title)
7581
fclose(in);
7682
fclose(out);
7783
remove(tempfile);
84+
G_free(tempfile);
7885

7986
return 1;
8087
}

0 commit comments

Comments
 (0)