mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 21:58:22 +01:00
Fix some memory leaks (Issue #23)
This commit is contained in:
parent
f3689d6b3d
commit
095a4c10d4
@ -7,6 +7,8 @@ v1.0.0 (TBD)
|
|||||||
|
|
||||||
- Added `pdfioFileCreateOutput` API to support streaming output of PDF
|
- Added `pdfioFileCreateOutput` API to support streaming output of PDF
|
||||||
(Issue #21)
|
(Issue #21)
|
||||||
|
- Fixed `all-shared` target (Issue #22)
|
||||||
|
- Fixed memory leaks (Issue #23)
|
||||||
- Fixed some issues identified by a Coverity scan.
|
- Fixed some issues identified by a Coverity scan.
|
||||||
|
|
||||||
|
|
||||||
|
3
Makefile
3
Makefile
@ -118,6 +118,9 @@ install-shared:
|
|||||||
test: testpdfio
|
test: testpdfio
|
||||||
./testpdfio
|
./testpdfio
|
||||||
|
|
||||||
|
valgrind: testpdfio
|
||||||
|
valgrind --leak-check=full ./testpdfio
|
||||||
|
|
||||||
|
|
||||||
# pdfio library
|
# pdfio library
|
||||||
libpdfio.a: $(LIBOBJS)
|
libpdfio.a: $(LIBOBJS)
|
||||||
|
@ -357,6 +357,15 @@ _pdfioArrayDebug(pdfio_array_t *a, // I - Array
|
|||||||
void
|
void
|
||||||
_pdfioArrayDelete(pdfio_array_t *a) // I - Array
|
_pdfioArrayDelete(pdfio_array_t *a) // I - Array
|
||||||
{
|
{
|
||||||
|
size_t i; // Looping var
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < a->num_values; i ++)
|
||||||
|
{
|
||||||
|
if (a->values[i].type == PDFIO_VALTYPE_BINARY)
|
||||||
|
free(a->values[i].value.binary.data);
|
||||||
|
}
|
||||||
|
|
||||||
if (a)
|
if (a)
|
||||||
free(a->values);
|
free(a->values);
|
||||||
|
|
||||||
|
@ -80,6 +80,8 @@ pdfioStreamClose(pdfio_stream_t *st) // I - Stream
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deflateEnd(&st->flate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the length of this stream...
|
// Save the length of this stream...
|
||||||
|
26
testpdfio.c
26
testpdfio.c
@ -734,7 +734,7 @@ do_unit_tests(void)
|
|||||||
puts("\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
// Test the value parsers for edge cases...
|
// Test the value parsers for edge cases...
|
||||||
fputs("_pdfioValueRead(cid_dict): ", stdout);
|
fputs("_pdfioValueRead(cid_dict): ", stdout);
|
||||||
@ -748,43 +748,51 @@ do_unit_tests(void)
|
|||||||
puts("\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
// Create a new PDF file...
|
// Create a new PDF file...
|
||||||
fputs("pdfioFileCreate(\"testpdfio-out.pdf\", ...): ", stdout);
|
fputs("pdfioFileCreate(\"testpdfio-out.pdf\", ...): ", stdout);
|
||||||
if ((outpdf = pdfioFileCreate("testpdfio-out.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
if ((outpdf = pdfioFileCreate("testpdfio-out.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||||
puts("PASS");
|
puts("PASS");
|
||||||
else
|
else
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
if (write_unit_file(inpdf, outpdf, &num_pages, &first_image))
|
if (write_unit_file(inpdf, outpdf, &num_pages, &first_image))
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
if (read_unit_file("testpdfio-out.pdf", num_pages, first_image, false))
|
if (read_unit_file("testpdfio-out.pdf", num_pages, first_image, false))
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
// Create a new PDF file...
|
// Create a new PDF file...
|
||||||
if ((outfd = open("testpdfio-out2.pdf", O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666)) < 0)
|
if ((outfd = open("testpdfio-out2.pdf", O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666)) < 0)
|
||||||
{
|
{
|
||||||
perror("Unable to open \"testpdfio-out2.pdf\"");
|
perror("Unable to open \"testpdfio-out2.pdf\"");
|
||||||
return (1);
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs("pdfioFileCreateOutput(...): ", stdout);
|
fputs("pdfioFileCreateOutput(...): ", stdout);
|
||||||
if ((outpdf = pdfioFileCreateOutput((pdfio_output_cb_t)output_cb, &outfd, NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
if ((outpdf = pdfioFileCreateOutput((pdfio_output_cb_t)output_cb, &outfd, NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||||
puts("PASS");
|
puts("PASS");
|
||||||
else
|
else
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
if (write_unit_file(inpdf, outpdf, &num_pages, &first_image))
|
if (write_unit_file(inpdf, outpdf, &num_pages, &first_image))
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
close(outfd);
|
close(outfd);
|
||||||
|
|
||||||
if (read_unit_file("testpdfio-out2.pdf", num_pages, first_image, true))
|
if (read_unit_file("testpdfio-out2.pdf", num_pages, first_image, true))
|
||||||
return (1);
|
goto fail;
|
||||||
|
|
||||||
|
pdfioFileClose(inpdf);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
|
||||||
|
pdfioFileClose(inpdf);
|
||||||
|
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user