From 8e575c268b394c043607d9f0d9233745538e2887 Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Thu, 16 Jan 2025 03:56:49 -0500 Subject: [PATCH] v.to.rast: Fix Resource Leak issue in do_areas.c (#4957) * Fix Resource Leak issue * Suggested changes --- vector/v.to.rast/do_areas.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vector/v.to.rast/do_areas.c b/vector/v.to.rast/do_areas.c index c3be7f5c18d..413ab8346d4 100644 --- a/vector/v.to.rast/do_areas.c +++ b/vector/v.to.rast/do_areas.c @@ -94,13 +94,14 @@ int sort_areas(struct Map_info *Map, struct line_pnts *Points, int field, CELL cat; G_begin_polygon_area_calculations(); - Cats = Vect_new_cats_struct(); /* first count valid areas */ nareas = Vect_get_num_areas(Map); if (nareas == 0) return 0; + Cats = Vect_new_cats_struct(); + /* allocate list to hold valid area info */ list = (struct list *)G_calloc(nareas * sizeof(char), sizeof(struct list)); @@ -155,6 +156,7 @@ int sort_areas(struct Map_info *Map, struct line_pnts *Points, int field, /* sort the list by size */ qsort(list, nareas * sizeof(char), sizeof(struct list), compare); } + Vect_destroy_cats_struct(Cats); return nareas_selected; }