Commit 43a88e1d285103f1b610161e91ba1a0375e4fc11
1 parent
638bf5f9
Tweak #1287 comments
Showing
3 changed files
with
9 additions
and
7 deletions
ChangeLog
| 1 | 2024-09-20 Chao Li <mslichao@outlook.com> | 1 | 2024-09-20 Chao Li <mslichao@outlook.com> |
| 2 | 2 | ||
| 3 | - * Add C API qpdf_oh_free_buffer to release memory allocated by | ||
| 4 | - stream data functions. | 3 | + * Add C API function qpdf_oh_free_buffer to release memory allocated |
| 4 | + by stream data functions. | ||
| 5 | 5 | ||
| 6 | 2024-08-25 M Holger <m.holger@qpdf.org> | 6 | 2024-08-25 M Holger <m.holger@qpdf.org> |
| 7 | 7 |
include/qpdf/qpdf-c.h
| @@ -927,10 +927,11 @@ extern "C" { | @@ -927,10 +927,11 @@ extern "C" { | ||
| 927 | QPDF_ERROR_CODE qpdf_oh_get_page_content_data( | 927 | QPDF_ERROR_CODE qpdf_oh_get_page_content_data( |
| 928 | qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len); | 928 | qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len); |
| 929 | 929 | ||
| 930 | - /* Call free to release the buffer allocated with malloc. This function can be used to free | ||
| 931 | - * buffers that were dynamically allocated by qpdf functions such as qpdf_oh_get_stream_data | ||
| 932 | - * or qpdf_oh_get_page_content_data. The caller is responsible for calling qpdf_oh_free_buffer | ||
| 933 | - * to manage memory properly and avoid memory leaks. | 930 | + /* Call free to release a buffer allocated with malloc. This function can be used to free |
| 931 | + * buffers that were dynamically allocated by qpdf functions such as qpdf_oh_get_stream_data or | ||
| 932 | + * qpdf_oh_get_page_content_data. The caller is responsible for calling qpdf_oh_free_buffer (or | ||
| 933 | + * calling free directly) to manage memory properly and avoid memory leaks. This function has no | ||
| 934 | + * equivalent in the C++ API. | ||
| 934 | */ | 935 | */ |
| 935 | QPDF_DLL | 936 | QPDF_DLL |
| 936 | void qpdf_oh_free_buffer(unsigned char** bufp); | 937 | void qpdf_oh_free_buffer(unsigned char** bufp); |
qpdf/qpdf-ctest.c
| @@ -1152,6 +1152,7 @@ test38(char const* infile, char const* password, char const* outfile, char const | @@ -1152,6 +1152,7 @@ test38(char const* infile, char const* password, char const* outfile, char const | ||
| 1152 | assert(len == 53); | 1152 | assert(len == 53); |
| 1153 | assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234)); | 1153 | assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234)); |
| 1154 | qpdf_oh_free_buffer(&buf); | 1154 | qpdf_oh_free_buffer(&buf); |
| 1155 | + assert(!buf); | ||
| 1155 | 1156 | ||
| 1156 | /* Test whether filterable */ | 1157 | /* Test whether filterable */ |
| 1157 | QPDF_BOOL filtered = QPDF_FALSE; | 1158 | QPDF_BOOL filtered = QPDF_FALSE; |
| @@ -1169,7 +1170,7 @@ test38(char const* infile, char const* password, char const* outfile, char const | @@ -1169,7 +1170,7 @@ test38(char const* infile, char const* password, char const* outfile, char const | ||
| 1169 | assert(qpdf_oh_get_page_content_data(qpdf, page2, &buf2, &len) == 0); | 1170 | assert(qpdf_oh_get_page_content_data(qpdf, page2, &buf2, &len) == 0); |
| 1170 | assert(len == 47); | 1171 | assert(len == 47); |
| 1171 | assert(memcmp(buf, buf2, len) == 0); | 1172 | assert(memcmp(buf, buf2, len) == 0); |
| 1172 | - qpdf_oh_free_buffer(&buf); | 1173 | + free(buf); |
| 1173 | qpdf_oh_free_buffer(&buf2); | 1174 | qpdf_oh_free_buffer(&buf2); |
| 1174 | 1175 | ||
| 1175 | /* errors */ | 1176 | /* errors */ |