Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/vector/Vlib: Fix Resource Leak issue in break_polygons.c #4612

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading