Fix memory leak and data type.
Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
parent
63728e1340
commit
ac3b1dda63
6 changed files with 36 additions and 7 deletions
|
@ -45,7 +45,7 @@ typedef struct _object_outline_tree_t {
|
||||||
} object_outline_tree_t;
|
} object_outline_tree_t;
|
||||||
|
|
||||||
typedef enum _hn_code {
|
typedef enum _hn_code {
|
||||||
JBIG,
|
JBIG, /* Inverted */
|
||||||
DCT_0,
|
DCT_0,
|
||||||
DCT_1, /* Inverted */
|
DCT_1, /* Inverted */
|
||||||
JBIG2,
|
JBIG2,
|
||||||
|
|
|
@ -419,8 +419,14 @@ cnki_pdf(cnki_t **param)
|
||||||
if ((*param)->stat > 1)
|
if ((*param)->stat > 1)
|
||||||
printf("Deleting xref object\n");
|
printf("Deleting xref object\n");
|
||||||
|
|
||||||
|
pdf_object_t *tmp;
|
||||||
|
|
||||||
|
pdf_get_obj(&pdf, xref, &tmp);
|
||||||
pdf_obj_del(&pdf, xref);
|
pdf_obj_del(&pdf, xref);
|
||||||
|
|
||||||
|
tmp->next = NULL;
|
||||||
|
pdf_obj_destroy(&tmp);
|
||||||
|
|
||||||
if ((*param)->stat > 0)
|
if ((*param)->stat > 0)
|
||||||
printf("Deleted xref object\n");
|
printf("Deleted xref object\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -120,7 +120,7 @@ pdf_obj_add(pdf_object_t **pdf, int id,
|
||||||
if ((*pdf)->stream == NULL)
|
if ((*pdf)->stream == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
memcpy((*pdf)->stream, stream, (*pdf)->stream_size);
|
memcpy((*pdf)->stream, stream, stream_size);
|
||||||
(*pdf)->stream[(*pdf)->stream_size - 1] = '\n';
|
(*pdf)->stream[(*pdf)->stream_size - 1] = '\n';
|
||||||
} else {
|
} else {
|
||||||
(*pdf)->stream_size = 0;
|
(*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_size = stream_size + 1;
|
||||||
ptr->stream = ret;
|
ptr->stream = ret;
|
||||||
|
|
||||||
memcpy(ptr->stream, stream, ptr->stream_size);
|
memcpy(ptr->stream, stream, stream_size);
|
||||||
ptr->stream[ptr->stream_size - 1] = '\n';
|
ptr->stream[ptr->stream_size - 1] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,26 @@ _outline(pdf_object_t **pdf, object_outline_tree_t **outline_tree, int id, int *
|
||||||
return 0;
|
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
|
int
|
||||||
pdf_cnki_outline(pdf_object_t **pdf, object_outline_t **outline, int **ids)
|
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;
|
int *ret;
|
||||||
|
|
||||||
_outline(pdf, &outline_tree->left, outline_tree->id, &ret);
|
_outline(pdf, &outline_tree->left, outline_tree->id, &ret);
|
||||||
|
_outline_free(&outline_tree);
|
||||||
free(outline_tree);
|
|
||||||
|
|
||||||
snprintf(buf, 128,
|
snprintf(buf, 128,
|
||||||
"<<\n/Type Outlines\n/First %d 0 R\n/Last %d 0 R\n/Count %d\n>>",
|
"<<\n/Type Outlines\n/First %d 0 R\n/Last %d 0 R\n/Count %d\n>>",
|
||||||
|
|
|
@ -136,7 +136,7 @@ pdf_get_free_ids(pdf_object_t **pdf, int **ids, int count)
|
||||||
if (i != id) {
|
if (i != id) {
|
||||||
(*ids)[pos] = i;
|
(*ids)[pos] = i;
|
||||||
|
|
||||||
if (pos == count)
|
if (pos == count - 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -138,7 +138,11 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref)
|
||||||
int buf_size;
|
int buf_size;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
|
#ifdef __ILP32__
|
||||||
|
buf_size = snprintf(buf, 64, "%x%x", timestamp, size);
|
||||||
|
#else
|
||||||
buf_size = snprintf(buf, 64, "%lx%x", timestamp, size);
|
buf_size = snprintf(buf, 64, "%lx%x", timestamp, size);
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned char str[64];
|
unsigned char str[64];
|
||||||
memcpy(str, buf, 64);
|
memcpy(str, buf, 64);
|
||||||
|
|
Loading…
Reference in a new issue