From 43a88e1d285103f1b610161e91ba1a0375e4fc11 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 27 Sep 2024 11:58:46 +0100 Subject: [PATCH] Tweak #1287 comments --- ChangeLog | 4 ++-- include/qpdf/qpdf-c.h | 9 +++++---- qpdf/qpdf-ctest.c | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 978c1bb4..ba03fe89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2024-09-20 Chao Li - * Add C API qpdf_oh_free_buffer to release memory allocated by - stream data functions. + * Add C API function qpdf_oh_free_buffer to release memory allocated + by stream data functions. 2024-08-25 M Holger diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index b295d52f..3dcc788f 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -927,10 +927,11 @@ extern "C" { QPDF_ERROR_CODE qpdf_oh_get_page_content_data( qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len); - /* Call free to release the buffer allocated with malloc. This function can be used to free - * buffers that were dynamically allocated by qpdf functions such as qpdf_oh_get_stream_data - * or qpdf_oh_get_page_content_data. The caller is responsible for calling qpdf_oh_free_buffer - * to manage memory properly and avoid memory leaks. + /* Call free to release a buffer allocated with malloc. This function can be used to free + * buffers that were dynamically allocated by qpdf functions such as qpdf_oh_get_stream_data or + * qpdf_oh_get_page_content_data. The caller is responsible for calling qpdf_oh_free_buffer (or + * calling free directly) to manage memory properly and avoid memory leaks. This function has no + * equivalent in the C++ API. */ QPDF_DLL void qpdf_oh_free_buffer(unsigned char** bufp); diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c index 73e56dda..09d0a92a 100644 --- a/qpdf/qpdf-ctest.c +++ b/qpdf/qpdf-ctest.c @@ -1152,6 +1152,7 @@ test38(char const* infile, char const* password, char const* outfile, char const assert(len == 53); assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234)); qpdf_oh_free_buffer(&buf); + assert(!buf); /* Test whether filterable */ QPDF_BOOL filtered = QPDF_FALSE; @@ -1169,7 +1170,7 @@ test38(char const* infile, char const* password, char const* outfile, char const assert(qpdf_oh_get_page_content_data(qpdf, page2, &buf2, &len) == 0); assert(len == 47); assert(memcmp(buf, buf2, len) == 0); - qpdf_oh_free_buffer(&buf); + free(buf); qpdf_oh_free_buffer(&buf2); /* errors */