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

lib/ogsf: Fix Resource Leak issue in gp3.c #4977

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
43 changes: 28 additions & 15 deletions lib/ogsf/gp3.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,16 @@ geopoint *Gp_load_sites(const char *name, int *nsites, int *has_z)
*has_z = 1;
ndim = 3;
}
char *mname = G_fully_qualified_name(name, mapset)

while (eof == 0) {
ShubhamDesai marked this conversation as resolved.
Show resolved Hide resolved
ltype = Vect_read_next_line(&map, Points, Cats);
switch (ltype) {
case -1: {
G_warning(_("Unable to read vector map <%s>"),
G_fully_qualified_name(name, mapset));
G_warning(_("Unable to read vector map <%s>"), mname);
G_free(mname);
G_free(top);
G_free(gpt);
return NULL;
}
case -2: /* EOF */
Expand Down Expand Up @@ -146,12 +149,14 @@ geopoint *Gp_load_sites(const char *name, int *nsites, int *has_z)
if (!np) {
G_warning(
_("No points from vector map <%s> fall within current region"),
G_fully_qualified_name(name, mapset));
mname);
G_free(mname);
G_free(top);
return (NULL);
}
else {
G_message(_("Vector map <%s> loaded (%d points)"),
G_fully_qualified_name(name, mapset), np);
G_message(_("Vector map <%s> loaded (%d points)"), mname, np);
G_free(mname);
}

*nsites = np;
Expand Down Expand Up @@ -179,8 +184,9 @@ int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
int red, blu, grn;
const char *str;
const char *mapset;
char *fname;

dbDriver *driver;
dbDriver *driver = NULL;
dbValue value;

if (!gp || !gp->tstyle || !gp->filename)
Expand Down Expand Up @@ -208,8 +214,9 @@ int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Fi->database, Fi->driver);
}
G_message(_("Loading thematic points layer <%s>..."),
G_fully_qualified_name(gp->filename, mapset));
fname = G_fully_qualified_name(gp->filename, mapset);
G_message(_("Loading thematic points layer <%s>..."), fname);
G_free(fname);
npts = nskipped = 0;
for (gpt = gp->points; gpt; gpt = gpt->next) {
gpt->style = (gvstyle *)G_malloc(sizeof(gvstyle));
Expand Down Expand Up @@ -241,13 +248,15 @@ int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
((int)((blu) << 16) & BLU_MASK);
}
if (gp->tstyle->color_column) {
nvals = db_select_value(driver, Fi->table, Fi->key, cat,
gp->tstyle->color_column, &value);
if (nvals < 1)
continue;
str = db_get_value_string(&value);
if (!str)
continue;
if (driver) {
ShubhamDesai marked this conversation as resolved.
Show resolved Hide resolved
nvals = db_select_value(driver, Fi->table, Fi->key, cat,
gp->tstyle->color_column, &value);
if (nvals < 1)
continue;
str = db_get_value_string(&value);
if (!str)
continue;
}
if (G_str_to_color(str, &red, &grn, &blu) != 1) {
G_warning(_("Invalid color definition (%s)"), str);
gpt->style->color = gp->style->color;
Expand Down Expand Up @@ -295,5 +304,9 @@ int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
_("%d points without category. "
"Unable to determine color rules for features without category."),
nskipped);
if (driver) {
db_close_database_shutdown_driver(driver);
Vect_destroy_field_info(Fi);
nilason marked this conversation as resolved.
Show resolved Hide resolved
}
return npts;
}
Loading