gbranden pushed a commit to branch master
in repository groff.
commit 0bf5a484b56a50166c3a6a360b4d0d7da1e36828
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Sep 10 06:36:43 2026 -0500
[libbib,indxbib]: Fix Savannah #68703 (1/4).
Fix mismatched memory allocation/deallocation techniques, which risks
undefined behavior (UB) in C++.
* src/libs/libbib/search.cpp: Preprocessor-include C "<stdlib.h>" header
file for `free()` symbol.
(search_list_iterator::~search_list_iterator): Deallocate `query` with
free(3) rather than `delete[]`.
---
ChangeLog | 10 ++++++++++
src/include/search.h | 2 +-
src/libs/libbib/search.cpp | 3 ++-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b28830e12..ed916b85e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2026-09-10 G. Branden Robinson <[email protected]>
+
+ [libbib]: Fix mismatched memory allocation/deallocation
+ techniques, which risks undefined behavior (UB) in C++.
+
+ * src/libs/libbib/search.cpp: Preprocessor-include C
+ "<stdlib.h>" header file for `free()` symbol.
+ (search_list_iterator::~search_list_iterator): Deallocate
+ `query` with free(3) rather than `delete[]`.
+
2026-09-12 G. Branden Robinson <[email protected]>
[lookbib]: Update and resync usage message and man page
diff --git a/src/include/search.h b/src/include/search.h
index d979d0286..b8f033318 100644
--- a/src/include/search.h
+++ b/src/include/search.h
@@ -58,7 +58,7 @@ class search_list_iterator {
search_list *list;
search_item *ptr;
search_item_iterator *iter;
- char *query;
+ char *query; // to be freed with free()
linear_searcher searcher;
public:
search_list_iterator(search_list *, const char *query);
diff --git a/src/libs/libbib/search.cpp b/src/libs/libbib/search.cpp
index 4ed8b412d..847f8b353 100644
--- a/src/libs/libbib/search.cpp
+++ b/src/libs/libbib/search.cpp
@@ -23,6 +23,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <assert.h>
#include <errno.h>
+#include <stdlib.h> // free()
#include <string.h> // strchr(), strcmp(), strerror(), strlen()
#include "lib.h"
@@ -92,7 +93,7 @@ search_list_iterator::search_list_iterator(search_list *p,
const char *q)
search_list_iterator::~search_list_iterator()
{
list->niterators -= 1;
- delete[] query;
+ free(query);
delete iter;
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit