Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

g.proj: fix resource leaks #5042

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion general/g.proj/datumtrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ int set_datum(char *datum)
/* Destroy original key/value structure and replace with new one */
G_free_key_value(projinfo);
projinfo = temp_projinfo;
G_free(dstruct.ellps);
G_free(dstruct.longname);
G_free(dstruct.name);

return 1;
}
Expand Down Expand Up @@ -188,8 +191,10 @@ int set_datumtrans(int datumtrans, int force)
do {
struct gpj_datum_transform_list *old = list;

if (list->count == datumtrans)
if (list->count == datumtrans) {
G_free(chosenparams);
chosenparams = G_store(list->params);
}
list = list->next;
GPJ_free_datum_transform(old);
} while (list != NULL);
Expand Down
1 change: 1 addition & 0 deletions general/g.proj/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int input_wkt(char *wktfile)
#else
OSRExportToPrettyWkt(hSRS, &tmpwkt, FALSE);
#endif
G_free(projwkt);
projwkt = G_store(tmpwkt);
CPLFree(tmpwkt);
set_authnamecode(hSRS);
Expand Down
12 changes: 9 additions & 3 deletions general/g.proj/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void print_projinfo(int shell)
/* DEPRECATED: datum transformation is handled by PROJ */
void print_datuminfo(void)
{
char *datum, *params;
char *datum = NULL, *params = NULL;
struct gpj_datum dstruct;
int validdatum = 0;

Expand Down Expand Up @@ -126,13 +126,16 @@ void print_datuminfo(void)
if (validdatum > 0)
GPJ_free_datum(&dstruct);

G_free(datum);
G_free(params);

return;
}

/* print input projection information in PROJ format */
void print_proj4(int dontprettify)
{
struct pj_info pjinfo;
struct pj_info pjinfo = {0};
char *i, *projstrmod;
const char *projstr;
const char *unfact;
Expand Down Expand Up @@ -169,7 +172,7 @@ void print_proj4(int dontprettify)
if (pj_get_kv(&pjinfo, projinfo, projunits) == -1)
G_fatal_error(
_("Unable to convert projection information to PROJ format"));
projstr = pjinfo.def;
projstr = G_store(pjinfo.def);
#if PROJ_VERSION_MAJOR >= 5
proj_destroy(pjinfo.pj);
#else
Expand Down Expand Up @@ -199,6 +202,9 @@ void print_proj4(int dontprettify)
}
fputc('\n', stdout);
G_free(projstrmod);
G_free(pjinfo.srid);
G_free(pjinfo.def);
G_free((void *)projstr);

return;
}
Expand Down
Loading