Skip to content

Commit cb0dc5c

Browse files
Fix memory leak with php7 serialization
Fixes phpredis#786
1 parent 12453fc commit cb0dc5c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111
#include <ext/standard/php_smart_string.h>
1212
#include <ext/standard/php_var.h>
13+
#include <zend_smart_str.h>
1314
#ifdef HAVE_REDIS_IGBINARY
1415
#include "igbinary/igbinary.h"
1516
#endif
@@ -2023,14 +2024,14 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
20232024
return 1;
20242025

20252026
case REDIS_SERIALIZER_PHP:
2026-
20272027
PHP_VAR_SERIALIZE_INIT(ht);
20282028
php_var_serialize(&sstr, z, &ht TSRMLS_CC);
2029-
*val = sstr.s->val;
2029+
*val = estrndup(sstr.s->val, sstr.s->len);
20302030
*val_len = sstr.s->len;
2031+
smart_str_free(&sstr);
20312032
PHP_VAR_SERIALIZE_DESTROY(ht);
20322033

2033-
return 0;
2034+
return 1;
20342035

20352036
case REDIS_SERIALIZER_IGBINARY:
20362037
#ifdef HAVE_REDIS_IGBINARY

0 commit comments

Comments
 (0)