Skip to content

Commit

Permalink
lib/vector/Vlib: Fix Resource Leak issues in break_polygons.c (#4612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamDesai authored Nov 5, 2024
1 parent 847944e commit 3307797
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/vector/Vlib/break_polygons.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <unistd.h>
#include <math.h>
#include <errno.h>
#include <string.h>
#include <grass/vector.h>
#include <grass/glocale.h>

Expand Down Expand Up @@ -131,11 +132,19 @@ void Vect_break_polygons_file(struct Map_info *Map, int type,
filename = G_tempfile();
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
RTree = RTreeCreateTree(fd, 0, 2);
remove(filename);
(void)remove(filename);
G_free(filename);

filename = G_tempfile();
xpntfd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
remove(filename);
if (xpntfd < 0) {
close(RTree->fd);
G_free(filename);
G_fatal_error(_("Failed to create xpnt temporary file: %s"),
strerror(errno));
}
(void)remove(filename);
G_free(filename);

BPoints = Vect_new_line_struct();
Points = Vect_new_line_struct();
Expand Down Expand Up @@ -651,6 +660,7 @@ void Vect_break_polygons_mem(struct Map_info *Map, int type,
Vect_destroy_line_struct(Points);
Vect_destroy_line_struct(BPoints);
Vect_destroy_cats_struct(Cats);
Vect_destroy_cats_struct(ErrCats);
G_verbose_message(_("Breaks: %d"), nbreaks);
}

Expand Down

0 comments on commit 3307797

Please sign in to comment.