Skip to content

Commit eae5642

Browse files
committed
thdat02: don't try to free() a mapping
1 parent b4023a7 commit eae5642

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

thtk/thdat02.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ th02_read(
138138
ret = thtk_io_write(output, data, entry->zsize, error);
139139
thtk_io_unmap(thdat->stream, data);
140140
} else {
141-
thtk_io_t* data_stream = thtk_io_open_memory(data, entry->zsize, error);
141+
/* FIXME: ouch, an unnecessary copy, due to thtk_io_open_memory taking ownership */
142+
void *data2 = malloc(entry->zsize);
143+
if (!data2)
144+
return -1;
145+
memcpy(data2, data, entry->zsize);
146+
147+
thtk_io_t* data_stream = thtk_io_open_memory(data2, entry->zsize, error);
142148
if (!data_stream)
143149
return -1;
144150
ret = thtk_unrle(data_stream, entry->zsize, output, error);

0 commit comments

Comments
 (0)