Skip to content

Commit 1857042

Browse files
author
Shubham Vasudeo Desai
committed
Fix Resource Leak Issue
1 parent 366fcda commit 1857042

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/vector/Vlib/array.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ int Vect_set_varray_from_cat_list(struct Map_info *Map, int field,
145145

146146
if (n > varray->size) { /* not enough space */
147147
G_warning(_("Not enough space in vector array"));
148+
Vect_destroy_cats_struct(Cats);
148149
return 0;
149150
}
150151

@@ -168,6 +169,7 @@ int Vect_set_varray_from_cat_list(struct Map_info *Map, int field,
168169

169170
if (n > varray->size) { /* not enough space */
170171
G_warning(_("Not enough space in vector array"));
172+
Vect_destroy_cats_struct(Cats);
171173
return 0;
172174
}
173175

@@ -261,8 +263,6 @@ int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where,
261263
return 0;
262264
}
263265

264-
Cats = Vect_new_cats_struct();
265-
266266
/* Select categories from DB to array */
267267
Fi = Vect_get_field(Map, field);
268268
if (Fi == NULL) {
@@ -274,6 +274,7 @@ int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where,
274274
if (driver == NULL) {
275275
G_warning(_("Unable to open database <%s> by driver <%s>"),
276276
Fi->database, Fi->driver);
277+
Vect_destroy_field_info(Fi);
277278
return -1;
278279
}
279280

@@ -285,8 +286,11 @@ int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where,
285286
G_warning(
286287
_("Unable to select record from table <%s> (key %s, where %s)"),
287288
Fi->table, Fi->key, where);
289+
Vect_destroy_field_info(Fi);
288290
return -1;
289291
}
292+
Vect_destroy_field_info(Fi);
293+
Cats = Vect_new_cats_struct();
290294

291295
if (type & GV_AREA) { /* Areas */
292296
n = Vect_get_num_areas(Map);
@@ -297,6 +301,8 @@ int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where,
297301
it for all features. */
298302
if (n > varray->size) { /* not enough space */
299303
G_warning(_("Not enough space in vector array"));
304+
Vect_destroy_cats_struct(Cats);
305+
G_free(cats);
300306
return 0;
301307
}
302308

@@ -329,6 +335,8 @@ int Vect_set_varray_from_db(struct Map_info *Map, int field, const char *where,
329335

330336
if (n > varray->size) { /* not enough space */
331337
G_warning(_("Not enough space in vector array"));
338+
Vect_destroy_cats_struct(Cats);
339+
G_free(cats);
332340
return 0;
333341
}
334342

0 commit comments

Comments
 (0)