mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Merge pull request #1287 from mslichao/mslichao/capifreebuf
Add C API qpdf_oh_free_buffer to release memory allocated by stream data functions
This commit is contained in:
commit
638bf5f9ae
@ -1,3 +1,8 @@
|
|||||||
|
2024-09-20 Chao Li <mslichao@outlook.com>
|
||||||
|
|
||||||
|
* Add C API qpdf_oh_free_buffer to release memory allocated by
|
||||||
|
stream data functions.
|
||||||
|
|
||||||
2024-08-25 M Holger <m.holger@qpdf.org>
|
2024-08-25 M Holger <m.holger@qpdf.org>
|
||||||
|
|
||||||
* Add new command-line arguments --remove-metadata and --remove-info
|
* Add new command-line arguments --remove-metadata and --remove-info
|
||||||
|
@ -927,6 +927,14 @@ extern "C" {
|
|||||||
QPDF_ERROR_CODE qpdf_oh_get_page_content_data(
|
QPDF_ERROR_CODE qpdf_oh_get_page_content_data(
|
||||||
qpdf_data qpdf, qpdf_oh page_oh, unsigned char** bufp, size_t* len);
|
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.
|
||||||
|
*/
|
||||||
|
QPDF_DLL
|
||||||
|
void qpdf_oh_free_buffer(unsigned char** bufp);
|
||||||
|
|
||||||
/* The data pointed to by bufp will be copied by the library. It does not need to remain valid
|
/* The data pointed to by bufp will be copied by the library. It does not need to remain valid
|
||||||
* after the call returns.
|
* after the call returns.
|
||||||
*/
|
*/
|
||||||
|
@ -1771,6 +1771,16 @@ qpdf_oh_get_page_content_data(qpdf_data qpdf, qpdf_oh page_oh, unsigned char** b
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
qpdf_oh_free_buffer(unsigned char** bufp)
|
||||||
|
{
|
||||||
|
QTC::TC("qpdf", "qpdf-c called qpdf_oh_free_buffer");
|
||||||
|
if (bufp && *bufp) {
|
||||||
|
free(*bufp);
|
||||||
|
*bufp = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
qpdf_oh_replace_stream_data(
|
qpdf_oh_replace_stream_data(
|
||||||
qpdf_data qpdf,
|
qpdf_data qpdf,
|
||||||
|
@ -1151,7 +1151,7 @@ test38(char const* infile, char const* password, char const* outfile, char const
|
|||||||
assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == 0);
|
assert(qpdf_oh_get_stream_data(qpdf, stream, qpdf_dl_none, 0, &buf, &len) == 0);
|
||||||
assert(len == 53);
|
assert(len == 53);
|
||||||
assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234));
|
assert(((int)buf[0] == 'x') && ((int)buf[1] == 0234));
|
||||||
free(buf);
|
qpdf_oh_free_buffer(&buf);
|
||||||
|
|
||||||
/* Test whether filterable */
|
/* Test whether filterable */
|
||||||
QPDF_BOOL filtered = QPDF_FALSE;
|
QPDF_BOOL filtered = QPDF_FALSE;
|
||||||
@ -1169,8 +1169,8 @@ 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(qpdf_oh_get_page_content_data(qpdf, page2, &buf2, &len) == 0);
|
||||||
assert(len == 47);
|
assert(len == 47);
|
||||||
assert(memcmp(buf, buf2, len) == 0);
|
assert(memcmp(buf, buf2, len) == 0);
|
||||||
free(buf);
|
qpdf_oh_free_buffer(&buf);
|
||||||
free(buf2);
|
qpdf_oh_free_buffer(&buf2);
|
||||||
|
|
||||||
/* errors */
|
/* errors */
|
||||||
printf("page content on broken page\n");
|
printf("page content on broken page\n");
|
||||||
|
@ -627,6 +627,7 @@ qpdf-c stream data filtered set 1
|
|||||||
qpdf-c stream data buf set 1
|
qpdf-c stream data buf set 1
|
||||||
qpdf-c called qpdf_oh_get_page_content_data 0
|
qpdf-c called qpdf_oh_get_page_content_data 0
|
||||||
qpdf-c called qpdf_oh_replace_stream_data 0
|
qpdf-c called qpdf_oh_replace_stream_data 0
|
||||||
|
qpdf-c called qpdf_oh_free_buffer 0
|
||||||
qpdf-c silence oh errors 0
|
qpdf-c silence oh errors 0
|
||||||
qpdf-c called qpdf_oh_get_binary_string_value 0
|
qpdf-c called qpdf_oh_get_binary_string_value 0
|
||||||
qpdf-c called qpdf_oh_get_binary_utf8_value 0
|
qpdf-c called qpdf_oh_get_binary_utf8_value 0
|
||||||
|
Loading…
Reference in New Issue
Block a user