-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||||||
#include <unistd.h> | ||||||||||
#include <math.h> | ||||||||||
#include <errno.h> | ||||||||||
#include <string.h> | ||||||||||
#include <grass/vector.h> | ||||||||||
#include <grass/glocale.h> | ||||||||||
|
||||||||||
|
@@ -130,12 +131,30 @@ void Vect_break_polygons_file(struct Map_info *Map, int type, | |||||||||
|
||||||||||
filename = G_tempfile(); | ||||||||||
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600); | ||||||||||
if (fd < 0) { | ||||||||||
G_free(filename); | ||||||||||
G_fatal_error(_("Failed to create temporary file: %s"), | ||||||||||
strerror(errno)); | ||||||||||
} | ||||||||||
RTree = RTreeCreateTree(fd, 0, 2); | ||||||||||
remove(filename); | ||||||||||
if (remove(filename) != 0) { | ||||||||||
G_warning(_("Failed to remove temporary file: %s"), filename); | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
As the above open may fail, this may too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||
G_free(filename); | ||||||||||
|
||||||||||
filename = G_tempfile(); | ||||||||||
xpntfd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600); | ||||||||||
remove(filename); | ||||||||||
if (xpntfd < 0) { | ||||||||||
RTreeDestroyTree(RTree); | ||||||||||
close(fd); | ||||||||||
G_free(filename); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need to free in-memory objects in case of G_fatal_error, the system will take care of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||
G_fatal_error(_("Failed to create xpnt temporary file: %s"), | ||||||||||
strerror(errno)); | ||||||||||
} | ||||||||||
if (remove(filename) != 0) { | ||||||||||
G_warning(_("Failed to remove xpnt temporary file: %s"), filename); | ||||||||||
} | ||||||||||
G_free(filename); | ||||||||||
|
||||||||||
BPoints = Vect_new_line_struct(); | ||||||||||
Points = Vect_new_line_struct(); | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, RTreeCreateTree creates in-memory RTree if open() fails. So, no error if it fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done