Make sure we free memory used for binary data.

This commit is contained in:
Michael R Sweet 2021-10-31 08:30:08 -04:00
parent 9014ab7a20
commit 9d121335f5
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244

View File

@ -44,6 +44,9 @@ _pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
if ((pair = (_pdfio_pair_t *)bsearch(&pkey, dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs)) != NULL) if ((pair = (_pdfio_pair_t *)bsearch(&pkey, dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs)) != NULL)
{ {
// Yes, remove it... // Yes, remove it...
if (pair->value.type == PDFIO_VALTYPE_BINARY)
free(pair->value.value.binary.data);
idx = (size_t)(pair - dict->pairs); idx = (size_t)(pair - dict->pairs);
dict->num_pairs --; dict->num_pairs --;
@ -187,7 +190,18 @@ void
_pdfioDictDelete(pdfio_dict_t *dict) // I - Dictionary _pdfioDictDelete(pdfio_dict_t *dict) // I - Dictionary
{ {
if (dict) if (dict)
{
size_t i; // Looping var
_pdfio_pair_t *pair; // Current pair
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i --, pair ++)
{
if (pair->value.type == PDFIO_VALTYPE_BINARY)
free(pair->value.value.binary.data);
}
free(dict->pairs); free(dict->pairs);
}
free(dict); free(dict);
} }
@ -836,6 +850,8 @@ _pdfioDictSetValue(
{ {
// Yes, replace the value... // Yes, replace the value...
PDFIO_DEBUG("_pdfioDictSetValue: Replacing existing value.\n"); PDFIO_DEBUG("_pdfioDictSetValue: Replacing existing value.\n");
if (pair->value.type == PDFIO_VALTYPE_BINARY)
free(pair->value.value.binary.data);
pair->value = *value; pair->value = *value;
return (true); return (true);
} }