Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c40fc1d

Browse files
LawnGnomemichael-grunder
authored andcommitted
Fix memory leak in redis_serialize().
redis_serialize() leaks the zend_string within z_copy in the redis_sock->serializer == REDIS_SERIALIZER_NONE case when z is not an IS_STRING. Instead, redis_serialize() should take a copy of the string, return that with the flag telling the caller to free the string when it's done with it, and destroy z_copy.
1 parent b09e07b commit c40fc1d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2019,9 +2019,10 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
20192019

20202020
/* return string */
20212021
convert_to_string(&z_copy);
2022-
*val = Z_STRVAL_P(&z_copy);
2022+
*val = estrndup(Z_STRVAL_P(&z_copy), Z_STRLEN_P(&z_copy));
20232023
*val_len = Z_STRLEN_P(&z_copy);
2024-
return 0;
2024+
zval_ptr_dtor(&z_copy);
2025+
return 1;
20252026

20262027
case REDIS_SERIALIZER_PHP:
20272028

0 commit comments

Comments
 (0)