Skip to content

Commit 1f8dde4

Browse files
committed
refactor redis_1_response + fix memory leak in redis_long_response
1 parent 18149e3 commit 1f8dde4

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

library.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,11 +1171,11 @@ PHP_REDIS_API void redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
11711171
}
11721172
} else {
11731173
if(ret > LONG_MAX) { /* overflow */
1174-
RETURN_STRINGL(response+1, response_len-1);
1174+
RETVAL_STRINGL(response + 1, response_len - 1);
11751175
} else {
1176-
efree(response);
1177-
RETURN_LONG((long)ret);
1176+
RETVAL_LONG((long)ret);
11781177
}
1178+
efree(response);
11791179
}
11801180
} else {
11811181
efree(response);
@@ -1321,39 +1321,22 @@ PHP_REDIS_API int redis_mbulk_reply_zipped_vals(INTERNAL_FUNCTION_PARAMETERS, Re
13211321
z_tab, UNSERIALIZE_VALS, SCORE_DECODE_NONE);
13221322
}
13231323

1324-
PHP_REDIS_API void redis_1_response(INTERNAL_FUNCTION_PARAMETERS,
1325-
RedisSock *redis_sock, zval *z_tab, void *ctx)
1324+
PHP_REDIS_API void
1325+
redis_1_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
13261326
{
1327-
13281327
char *response;
13291328
int response_len;
1330-
char ret;
1329+
zend_bool ret = 0;
13311330

1332-
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))
1333-
== NULL)
1334-
{
1335-
IF_NOT_ATOMIC() {
1336-
add_next_index_bool(z_tab, 0);
1337-
return;
1338-
} else {
1339-
RETURN_FALSE;
1340-
}
1331+
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) != NULL) {
1332+
ret = (response[1] == '1');
1333+
efree(response);
13411334
}
1342-
ret = response[1];
1343-
efree(response);
13441335

13451336
IF_NOT_ATOMIC() {
1346-
if(ret == '1') {
1347-
add_next_index_bool(z_tab, 1);
1348-
} else {
1349-
add_next_index_bool(z_tab, 0);
1350-
}
1337+
add_next_index_bool(z_tab, ret);
13511338
} else {
1352-
if (ret == '1') {
1353-
RETURN_TRUE;
1354-
} else {
1355-
RETURN_FALSE;
1356-
}
1339+
RETURN_BOOL(ret);
13571340
}
13581341
}
13591342

0 commit comments

Comments
 (0)