From 5850bb1454be52a6394e70fd48ef67e8599fe682 Mon Sep 17 00:00:00 2001 From: Lucas Holt Date: Sat, 28 Aug 2021 09:15:39 -0400 Subject: [PATCH] fix pointer issue with plist. (cherry picked from commit c4e19be238610bdad34506dc005a295d0c555526) --- libmport/plist.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libmport/plist.c b/libmport/plist.c index 9764918..a428da7 100644 --- a/libmport/plist.c +++ b/libmport/plist.c @@ -54,21 +54,26 @@ mport_assetlist_new(void) { /* free all the entries in the list, and then the list itself. */ MPORT_PUBLIC_API void mport_assetlist_free(mportAssetList *list) { - mportAssetListEntry *n = NULL; + mportAssetListEntry *n = NULL; + mportAssetList *list_orig; + list_orig = list; - while (!STAILQ_EMPTY(list)) { - n = STAILQ_FIRST(list); - STAILQ_REMOVE_HEAD(list, next); - free(n->data); + if (list == NULL) + return; + + while (!STAILQ_EMPTY(list)) { + n = STAILQ_FIRST(list); + STAILQ_REMOVE_HEAD(list, next); + free(n->data); free(n->checksum); free(n->owner); free(n->group); free(n->mode); /* type is not a pointer */ - free(n); - } + free(n); + } - free(list); + free(list_orig); } @@ -117,7 +122,7 @@ mport_parse_plistfile(FILE *fp, mportAssetList *list) { RETURN_ERROR(MPORT_ERR_FATAL, "Malformed plist file."); entry->checksum = NULL; /* checksum is only used by bundle read install */ - entry->type = parse_command(cmnd); + entry->type = parse_command(cmnd); if (entry->type == ASSET_FILE_OWNER_MODE) parse_file_owner_mode(&entry, cmnd); if (entry->type == ASSET_DIR_OWNER_MODE) {