diff options
author | yzrh <yzrh@noema.org> | 2022-12-22 11:22:41 +0000 |
---|---|---|
committer | yzrh <yzrh@noema.org> | 2022-12-22 19:48:48 +0000 |
commit | ac3b1dda63944f2cc8caaa52344774255e1956c8 (patch) | |
tree | 2fb8b24fbfe8002f39288926fa06c71100102868 /src | |
parent | 63728e1340a27b7ae629a747229871f3dc670de5 (diff) | |
download | melon-ac3b1dda63944f2cc8caaa52344774255e1956c8.tar.gz melon-ac3b1dda63944f2cc8caaa52344774255e1956c8.tar.zst |
Fix memory leak and data type.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/cnki.h | 2 | ||||
-rw-r--r-- | src/cnki_pdf.c | 6 | ||||
-rw-r--r-- | src/pdf.c | 4 | ||||
-rw-r--r-- | src/pdf_cnki.c | 23 | ||||
-rw-r--r-- | src/pdf_get.c | 2 | ||||
-rw-r--r-- | src/pdf_writer.c | 6 |
6 files changed, 36 insertions, 7 deletions
@@ -45,7 +45,7 @@ typedef struct _object_outline_tree_t { } object_outline_tree_t; typedef enum _hn_code { - JBIG, + JBIG, /* Inverted */ DCT_0, DCT_1, /* Inverted */ JBIG2, diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c index 6a7a317..dcf6d30 100644 --- a/src/cnki_pdf.c +++ b/src/cnki_pdf.c @@ -419,8 +419,14 @@ cnki_pdf(cnki_t **param) if ((*param)->stat > 1) printf("Deleting xref object\n"); + pdf_object_t *tmp; + + pdf_get_obj(&pdf, xref, &tmp); pdf_obj_del(&pdf, xref); + tmp->next = NULL; + pdf_obj_destroy(&tmp); + if ((*param)->stat > 0) printf("Deleted xref object\n"); } else { @@ -120,7 +120,7 @@ pdf_obj_add(pdf_object_t **pdf, int id, if ((*pdf)->stream == NULL) return 1; - memcpy((*pdf)->stream, stream, (*pdf)->stream_size); + memcpy((*pdf)->stream, stream, stream_size); (*pdf)->stream[(*pdf)->stream_size - 1] = '\n'; } else { (*pdf)->stream_size = 0; @@ -249,7 +249,7 @@ pdf_obj_replace(pdf_object_t **pdf, int id, ptr->stream_size = stream_size + 1; ptr->stream = ret; - memcpy(ptr->stream, stream, ptr->stream_size); + memcpy(ptr->stream, stream, stream_size); ptr->stream[ptr->stream_size - 1] = '\n'; } diff --git a/src/pdf_cnki.c b/src/pdf_cnki.c index 84274b8..a1c7a09 100644 --- a/src/pdf_cnki.c +++ b/src/pdf_cnki.c @@ -106,6 +106,26 @@ _outline(pdf_object_t **pdf, object_outline_tree_t **outline_tree, int id, int * return 0; } +static int +_outline_free(object_outline_tree_t **outline_tree) +{ + object_outline_tree_t *ptr = *outline_tree; + for (;;) { + if (ptr->right != NULL) + _outline_free(&ptr->right); + + if (ptr->left != NULL) { + ptr = ptr->left; + free(ptr->up); + } else { + free(ptr); + break; + } + } + + return 0; +} + int pdf_cnki_outline(pdf_object_t **pdf, object_outline_t **outline, int **ids) { @@ -119,8 +139,7 @@ pdf_cnki_outline(pdf_object_t **pdf, object_outline_t **outline, int **ids) int *ret; _outline(pdf, &outline_tree->left, outline_tree->id, &ret); - - free(outline_tree); + _outline_free(&outline_tree); snprintf(buf, 128, "<<\n/Type Outlines\n/First %d 0 R\n/Last %d 0 R\n/Count %d\n>>", diff --git a/src/pdf_get.c b/src/pdf_get.c index f72f4aa..4e1ec56 100644 --- a/src/pdf_get.c +++ b/src/pdf_get.c @@ -136,7 +136,7 @@ pdf_get_free_ids(pdf_object_t **pdf, int **ids, int count) if (i != id) { (*ids)[pos] = i; - if (pos == count) + if (pos == count - 1) return 0; pos++; diff --git a/src/pdf_writer.c b/src/pdf_writer.c index cd188fc..be64e49 100644 --- a/src/pdf_writer.c +++ b/src/pdf_writer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, yzrh <yzrh@noema.org> + * Copyright (c) 2020-2022, yzrh <yzrh@noema.org> * * SPDX-License-Identifier: Apache-2.0 */ @@ -138,7 +138,11 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref) int buf_size; char buf[64]; +#ifdef __ILP32__ + buf_size = snprintf(buf, 64, "%x%x", timestamp, size); +#else buf_size = snprintf(buf, 64, "%lx%x", timestamp, size); +#endif unsigned char str[64]; memcpy(str, buf, 64); |