Skip to content

Commit 762835c

Browse files
authored
Merge pull request #94 from chschneider/fix-memory-leak-uncompress
Fix a memory leak with zstd_uncompress/zstd_uncompress_dict
2 parents 1577e5d + dacc2b3 commit 762835c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

tests/memory_001.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
memory_usage regression in 0.15.0
3+
--FILE--
4+
<?php
5+
$start = memory_get_usage();
6+
zstd_uncompress(zstd_compress(str_repeat('a', 1000)));
7+
$end = memory_get_usage();
8+
echo ($end - $start) . "\n";
9+
?>
10+
--EXPECT--
11+
0

zstd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ ZEND_FUNCTION(zstd_uncompress)
527527
ctx.input.size = ZSTR_LEN(input);
528528
ctx.input.pos = 0;
529529

530-
ctx.output.dst = emalloc(size);
530+
ctx.output.dst = erealloc(ctx.output.dst, size);
531531
ctx.output.size = size;
532532
ctx.output.pos = 0;
533533

@@ -646,7 +646,7 @@ ZEND_FUNCTION(zstd_uncompress_dict)
646646
ctx.input.size = ZSTR_LEN(input);
647647
ctx.input.pos = 0;
648648

649-
ctx.output.dst = emalloc(size);
649+
ctx.output.dst = erealloc(ctx.output.dst, size);
650650
ctx.output.size = size;
651651
ctx.output.pos = 0;
652652

0 commit comments

Comments
 (0)