Skip to content

Commit

Permalink
lib/vector/Vlib: Fix Resource Leak issue in open_ogr.c (#4960)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Feb 4, 2025
1 parent 2619f91 commit 805aba1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/vector/Vlib/open_ogr.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ int V2_open_old_ogr(struct Map_info *Map)
Map->mapset);

if (Vect_open_fidx(Map, &(Map->fInfo.ogr.offset)) != 0) {
const char *map_name = Vect_get_full_name(Map);
G_warning(_("Unable to open feature index file for vector map <%s>"),
Vect_get_full_name(Map));
map_name);
G_free((void *)map_name);
G_zero(&(Map->fInfo.ogr.offset), sizeof(struct Format_info_offset));
}

Expand Down Expand Up @@ -268,14 +270,17 @@ int Vect_open_fidx(struct Map_info *Map, struct Format_info_offset *offset)
dig_file_init(&fp);
fp.file = G_fopen_old(elem, GV_FIDX_ELEMENT, Map->mapset);
if (fp.file == NULL) {
G_debug(1, "unable to open fidx file for vector map <%s>",
Vect_get_full_name(Map));
const char *map_name = Vect_get_full_name(Map);
G_debug(1, "unable to open fidx file for vector map <%s>", map_name);
G_free((void *)map_name);
return -1;
}

/* Header */
if (0 >= dig__fread_port_C(buf, 5, &fp))
if (0 >= dig__fread_port_C(buf, 5, &fp)) {
fclose(fp.file);
return -1;
}
Version_Major = buf[0];
Version_Minor = buf[1];
Back_Major = buf[2];
Expand All @@ -302,23 +307,29 @@ int Vect_open_fidx(struct Map_info *Map, struct Format_info_offset *offset)

/* Body */
/* bytes 6 - 9 : header size */
if (0 >= dig__fread_port_L(&length, 1, &fp))
if (0 >= dig__fread_port_L(&length, 1, &fp)) {
fclose(fp.file);
return -1;
}
G_debug(4, " header size %ld", length);

G_fseek(fp.file, length, SEEK_SET);

/* number of records */
if (0 >= dig__fread_port_I(&(offset->array_num), 1, &fp))
if (0 >= dig__fread_port_I(&(offset->array_num), 1, &fp)) {
fclose(fp.file);
return -1;
}

/* alloc space */
offset->array = (int *)G_malloc(offset->array_num * sizeof(int));
offset->array_alloc = offset->array_num;

/* offsets */
if (0 >= dig__fread_port_I(offset->array, offset->array_num, &fp))
if (0 >= dig__fread_port_I(offset->array, offset->array_num, &fp)) {
fclose(fp.file);
return -1;
}

fclose(fp.file);

Expand Down

0 comments on commit 805aba1

Please sign in to comment.