gbranden pushed a commit to branch master
in repository groff.
commit c2f0e424e4a2bdcd287c8be9957daf93a581673a
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jan 6 15:43:57 2021 +1100
src/libs/libgroff/relocate.cpp: Fix memory leak.
* src/libs/libgroff/relocate.cpp (set_current_prefix) [_WIN32]: Allocate
memory from heap for `curr_prefix` only on Windows; on other systems,
this file's searchpath() is used to populate `curr_prefix`, and that
function (except on Windows) performs its own allocation. Fixes
memory leak noted by Ingo Schwarze.
---
ChangeLog | 9 ++++++++-
src/libs/libgroff/relocate.cpp | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 03a23a8..75306ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,14 @@
* src/libs/libgroff/relocate.cpp (relocatep): Add assertion to
identify logic error if `curr_prefix` is unexpectedly a null
- pointer. See <https://savannah.gnu.org/bugs/?55475>.
+ pointer.
+ (set_current_prefix) [_WIN32]: Allocate memory from heap for
+ `curr_prefix` only on Windows; on other systems, this file's
+ searchpath() is used to populate `curr_prefix`, and that
+ function (except on Windows) performs its own allocation. Fixes
+ memory leak noted by Ingo Schwarze.
+
+ See <https://savannah.gnu.org/bugs/?55475>.
2021-01-06 Colin Watson <[email protected]>
diff --git a/src/libs/libgroff/relocate.cpp b/src/libs/libgroff/relocate.cpp
index e505bdf..298f693 100644
--- a/src/libs/libgroff/relocate.cpp
+++ b/src/libs/libgroff/relocate.cpp
@@ -160,11 +160,11 @@ char *msw2posixpath(char *path)
void set_current_prefix()
{
char *pathextstr;
- curr_prefix = new char[path_name_max()];
// Obtain the full path of the current binary;
// using GetModuleFileName on MS-Windows,
// and searching along PATH on other systems.
#ifdef _WIN32
+ curr_prefix = new char[path_name_max()];
int len = GetModuleFileName(0, curr_prefix, path_name_max());
if (len)
len = GetShortPathName(curr_prefix, curr_prefix, path_name_max());
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit