Skip to content

Commit c7ccd91

Browse files
authored
lib/ogsf: Fix Resource Leak Issue in gvl_calc.c (OSGeo#6169)
1 parent d1a44da commit c7ccd91

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/ogsf/gvl_calc.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ int gvl_isosurf_calc(geovol *gvol)
720720
}
721721
}
722722

723-
/* TODO: G_free() dbuff and need_update ??? */
723+
G_free(dbuff);
724+
G_free(need_update);
724725

725726
return (1);
726727
}
@@ -775,20 +776,23 @@ unsigned char gvl_read_char(int pos, const unsigned char *data)
775776
*/
776777
void gvl_align_data(int pos, unsigned char **data)
777778
{
778-
unsigned char *p = *data;
779-
779+
if (pos <= 0) {
780+
if (*data) {
781+
G_free(*data);
782+
*data = NULL;
783+
}
784+
return;
785+
}
780786
/* realloc memory to fit in data length */
781-
p = (unsigned char *)G_realloc(p, sizeof(unsigned char) *
782-
pos); /* G_fatal_error */
787+
unsigned char *p;
788+
p = (unsigned char *)G_realloc(*data, sizeof(unsigned char) *
789+
pos); /* G_fatal_error */
783790
if (!p) {
784791
return;
785792
}
786793

787794
G_debug(3, "gvl_align_data(): reallocate memory finally to : %d B", pos);
788795

789-
if (pos == 0)
790-
p = NULL;
791-
792796
*data = p;
793797

794798
return;

0 commit comments

Comments
 (0)