diff options
| author | 2017-01-28 05:20:44 +0100 | |
|---|---|---|
| committer | 2017-01-28 05:20:44 +0100 | |
| commit | 783777b8e1082a9275d2c6c1aa6b7996e9c4ff00 (patch) | |
| tree | 9ef81035620cb497a3a2cc49b062e4d8cbbc1f42 | |
| parent | 30e14a3ec62ddc37738b8afe2345413397410420 (diff) | |
| download | libplist-783777b8e1082a9275d2c6c1aa6b7996e9c4ff00.tar.gz libplist-783777b8e1082a9275d2c6c1aa6b7996e9c4ff00.tar.bz2 | |
bplist: Don't duplicate output buffer in plist_to_bin()
| -rw-r--r-- | src/bplist.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/bplist.c b/src/bplist.c index 0c57a75..64c9081 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -1154,6 +1154,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1154 | uint64_t offset = be64toh(offsets[i]); | 1154 | uint64_t offset = be64toh(offsets[i]); |
| 1155 | byte_array_append(bplist_buff, (uint8_t*)&offset + (sizeof(uint64_t) - offset_size), offset_size); | 1155 | byte_array_append(bplist_buff, (uint8_t*)&offset + (sizeof(uint64_t) - offset_size), offset_size); |
| 1156 | } | 1156 | } |
| 1157 | free(offsets); | ||
| 1157 | 1158 | ||
| 1158 | //setup trailer | 1159 | //setup trailer |
| 1159 | memset(trailer.unused, '\0', sizeof(trailer.unused)); | 1160 | memset(trailer.unused, '\0', sizeof(trailer.unused)); |
| @@ -1165,11 +1166,10 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1165 | 1166 | ||
| 1166 | byte_array_append(bplist_buff, &trailer, sizeof(bplist_trailer_t)); | 1167 | byte_array_append(bplist_buff, &trailer, sizeof(bplist_trailer_t)); |
| 1167 | 1168 | ||
| 1168 | //duplicate buffer | 1169 | //set output buffer and size |
| 1169 | *plist_bin = (char *) malloc(bplist_buff->len); | 1170 | *plist_bin = bplist_buff->data; |
| 1170 | memcpy(*plist_bin, bplist_buff->data, bplist_buff->len); | ||
| 1171 | *length = bplist_buff->len; | 1171 | *length = bplist_buff->len; |
| 1172 | 1172 | ||
| 1173 | bplist_buff->data = NULL; // make sure we don't free the output buffer | ||
| 1173 | byte_array_free(bplist_buff); | 1174 | byte_array_free(bplist_buff); |
| 1174 | free(offsets); | ||
| 1175 | } | 1175 | } |
