mirror of https://github.com/google/oss-fuzz.git
If mupdf throws an exception (extremely likely in when fuzzing), none of the resources such as the rendered pixmap, document or stream were reclaimed before exiting causing memory leaks. These leaks were blamed on the software itself, when it actually was the fuzzer implementation that leaked. Fix this by always cleaning up all resources.
This commit is contained in:
parent
9bac6ac046
commit
ad33fea957
|
@ -22,24 +22,33 @@
|
|||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
fz_context *ctx = fz_new_context(nullptr, nullptr, FZ_STORE_DEFAULT);
|
||||
fz_register_document_handlers(ctx);
|
||||
|
||||
fz_stream *stream = fz_open_memory(ctx, data, size);
|
||||
fz_pixmap *pix = NULL;
|
||||
fz_stream *stream = NULL;
|
||||
fz_document *doc = NULL;
|
||||
fz_pixmap *pix = NULL;
|
||||
|
||||
fz_var(stream);
|
||||
fz_var(doc);
|
||||
fz_var(pix);
|
||||
|
||||
fz_try(ctx) {
|
||||
fz_register_document_handlers(ctx);
|
||||
stream = fz_open_memory(ctx, data, size);
|
||||
doc = fz_open_document_with_stream(ctx, "pdf", stream);
|
||||
for (int i = 0; i < fz_count_pages(ctx, doc); i++) {
|
||||
pix = fz_new_pixmap_from_page_number(ctx, doc, i, fz_identity, fz_device_rgb(ctx), 0);
|
||||
fz_drop_pixmap(ctx, pix);
|
||||
pix = NULL;
|
||||
}
|
||||
}
|
||||
fz_catch(ctx) {}
|
||||
|
||||
if (doc) {
|
||||
fz_always(ctx) {
|
||||
fz_drop_pixmap(ctx, pix);
|
||||
fz_drop_document(ctx, doc);
|
||||
fz_drop_stream(ctx, stream);
|
||||
}
|
||||
fz_drop_stream(ctx, stream);
|
||||
fz_catch(ctx) {
|
||||
}
|
||||
|
||||
fz_drop_context(ctx);
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue