Skip to content

Commit 9cb2dc2

Browse files
committed
Fixed memory problems with the new serializer.
1 parent 6d1e805 commit 9cb2dc2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

library.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ PHPAPI void redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis
690690
IF_MULTI_OR_PIPELINE() {
691691
zval *z = NULL;
692692
if(redis_unserialize(redis_sock, response, response_len, &z TSRMLS_CC) == 1) {
693+
efree(response);
693694
add_next_index_zval(z_tab, z);
694695
} else {
695696
add_next_index_stringl(z_tab, response, response_len, 0);
@@ -698,6 +699,8 @@ PHPAPI void redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis
698699

699700
if(redis_unserialize(redis_sock, response, response_len, &return_value TSRMLS_CC) == 0) {
700701
RETURN_STRINGL(response, response_len, 0);
702+
} else {
703+
efree(response);
701704
}
702705
}
703706

@@ -891,6 +894,7 @@ redis_sock_read_multibulk_reply_loop(INTERNAL_FUNCTION_PARAMETERS, RedisSock *re
891894
if(response != NULL) {
892895
zval *z = NULL;
893896
if(redis_unserialize(redis_sock, response, response_len, &z TSRMLS_CC) == 1) {
897+
efree(response);
894898
add_next_index_zval(z_tab, z);
895899
} else {
896900
add_next_index_stringl(z_tab, response, response_len, 0);
@@ -938,6 +942,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
938942
if(response != NULL) {
939943
zval *z = NULL;
940944
if(redis_unserialize(redis_sock, response, response_len, &z TSRMLS_CC) == 1) {
945+
efree(response);
941946
add_assoc_zval_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), 1+Z_STRLEN_P(z_keys[i]), z);
942947
} else {
943948
add_assoc_stringl_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), 1+Z_STRLEN_P(z_keys[i]), response, response_len, 1);
@@ -956,7 +961,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
956961

957962
*return_value = *z_multi_result;
958963
//zval_copy_ctor(return_value);
959-
// efree(z_multi_result);
964+
efree(z_multi_result);
960965
return 0;
961966
}
962967

@@ -1064,6 +1069,7 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
10641069
var_hash.first_dtor = 0;
10651070
if(!php_var_unserialize(return_value, (const unsigned char**)&val,
10661071
(const unsigned char*)val + val_len, &var_hash TSRMLS_CC)) {
1072+
efree(*return_value);
10671073
ret = 0;
10681074
} else {
10691075
ret = 1;
@@ -1079,6 +1085,7 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
10791085
if(igbinary_unserialize((const uint8_t *)val, (size_t)val_len, return_value TSRMLS_CC) == 0) {
10801086
return 1;
10811087
}
1088+
efree(*return_value);
10821089
return 0;
10831090
break;
10841091
}

redis.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3695,16 +3695,16 @@ PHPAPI void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab, int
36953695
int hkey_len, hval_len;
36963696
unsigned long idx;
36973697
int type;
3698-
zval **z_value_pp;
3698+
zval **z_key_pp, **z_value_pp;
36993699

37003700
type = zend_hash_get_current_key_ex(keytable, &tablekey, &tablekey_len, &idx, 0, NULL);
3701-
if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
3701+
if(zend_hash_get_current_data(keytable, (void**)&z_key_pp) == FAILURE) {
37023702
continue; /* this should never happen, according to the PHP people. */
37033703
}
37043704

37053705
/* get current value, a key */
3706-
hkey = Z_STRVAL_PP(z_value_pp);
3707-
hkey_len = Z_STRLEN_PP(z_value_pp);
3706+
hkey = Z_STRVAL_PP(z_key_pp);
3707+
hkey_len = Z_STRLEN_PP(z_key_pp);
37083708

37093709
/* move forward */
37103710
zend_hash_move_forward(keytable);

0 commit comments

Comments
 (0)