Skip to content

Commit ebdc73b

Browse files
committed
Fix memory leaks
The zend_string from get_active_function_or_method_name() needs to be released
1 parent 72981f1 commit ebdc73b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,10 @@ PHP_METHOD(PDOStatement, fetchAll)
13431343

13441344
case PDO_FETCH_FUNC: /* Cannot be a default fetch mode */
13451345
if (ZEND_NUM_ARGS() != 2) {
1346+
zend_string *func = get_active_function_or_method_name();
13461347
zend_argument_count_error("%s() expects exactly 2 argument for PDO::FETCH_FUNC, %d given",
1347-
ZSTR_VAL(get_active_function_or_method_name()), ZEND_NUM_ARGS());
1348+
ZSTR_VAL(func), ZEND_NUM_ARGS());
1349+
zend_string_release(func);
13481350
RETURN_THROWS();
13491351
}
13501352
if (arg2 == NULL) {
@@ -1360,8 +1362,10 @@ PHP_METHOD(PDOStatement, fetchAll)
13601362

13611363
case PDO_FETCH_COLUMN:
13621364
if (ZEND_NUM_ARGS() > 2) {
1365+
zend_string *func = get_active_function_or_method_name();
13631366
zend_argument_count_error("%s() expects at most 2 argument for the fetch mode provided, %d given",
1364-
ZSTR_VAL(get_active_function_or_method_name()), ZEND_NUM_ARGS());
1367+
ZSTR_VAL(func), ZEND_NUM_ARGS());
1368+
zend_string_release(func);
13651369
RETURN_THROWS();
13661370
}
13671371
/* Is column index passed? */
@@ -1384,8 +1388,10 @@ PHP_METHOD(PDOStatement, fetchAll)
13841388
default:
13851389
/* No support for PDO_FETCH_INTO which takes 2 args??? */
13861390
if (ZEND_NUM_ARGS() > 1) {
1391+
zend_string *func = get_active_function_or_method_name();
13871392
zend_argument_count_error("%s() expects exactly 1 argument for the fetch mode provided, %d given",
1388-
ZSTR_VAL(get_active_function_or_method_name()), ZEND_NUM_ARGS());
1393+
ZSTR_VAL(func), ZEND_NUM_ARGS());
1394+
zend_string_release(func);
13891395
RETURN_THROWS();
13901396
}
13911397
}
@@ -1767,16 +1773,20 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, uint32_t total_num_args, zend_l
17671773
case PDO_FETCH_NAMED:
17681774
case PDO_FETCH_KEY_PAIR:
17691775
if (total_num_args != mode_arg_num) {
1776+
zend_string *func = get_active_function_or_method_name();
17701777
zend_argument_count_error("%s() expects exactly %d argument for the fetch mode provided, %d given",
1771-
ZSTR_VAL(get_active_function_or_method_name()), mode_arg_num, total_num_args);
1778+
ZSTR_VAL(func), mode_arg_num, total_num_args);
1779+
zend_string_release(func);
17721780
return false;
17731781
}
17741782
break;
17751783

17761784
case PDO_FETCH_COLUMN:
17771785
if (total_num_args != arg1_arg_num) {
1786+
zend_string *func = get_active_function_or_method_name();
17781787
zend_argument_count_error("%s() expects exactly %d argument for the fetch mode provided, %d given",
1779-
ZSTR_VAL(get_active_function_or_method_name()), arg1_arg_num, total_num_args);
1788+
ZSTR_VAL(func), arg1_arg_num, total_num_args);
1789+
zend_string_release(func);
17801790
return false;
17811791
}
17821792
if (Z_TYPE_P(arg1) != IS_LONG) {
@@ -1796,17 +1806,21 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, uint32_t total_num_args, zend_l
17961806
/* Gets its class name from 1st column */
17971807
if ((flags & PDO_FETCH_CLASSTYPE) == PDO_FETCH_CLASSTYPE) {
17981808
if (arg1 || constructor_args) {
1809+
zend_string *func = get_active_function_or_method_name();
17991810
zend_argument_count_error("%s() expects exactly %d argument for the fetch mode provided, %d given",
1800-
ZSTR_VAL(get_active_function_or_method_name()), mode_arg_num, total_num_args);
1811+
ZSTR_VAL(func), mode_arg_num, total_num_args);
1812+
zend_string_release(func);
18011813
return false;
18021814
}
18031815
stmt->fetch.cls.ce = NULL;
18041816
} else {
18051817
zend_class_entry *cep;
18061818

18071819
if (!arg1 || total_num_args > constructor_arg_num) {
1820+
zend_string *func = get_active_function_or_method_name();
18081821
zend_argument_count_error("%s() expects exactly %d argument for the fetch mode provided, %d given",
1809-
ZSTR_VAL(get_active_function_or_method_name()), constructor_arg_num, total_num_args);
1822+
ZSTR_VAL(func), constructor_arg_num, total_num_args);
1823+
zend_string_release(func);
18101824
return false;
18111825
}
18121826
if (Z_TYPE_P(arg1) != IS_STRING) {
@@ -1829,8 +1843,10 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, uint32_t total_num_args, zend_l
18291843

18301844
case PDO_FETCH_INTO:
18311845
if (total_num_args != arg1_arg_num) {
1846+
zend_string *func = get_active_function_or_method_name();
18321847
zend_argument_count_error("%s() expects exactly %d argument for the fetch mode provided, %d given",
1833-
ZSTR_VAL(get_active_function_or_method_name()), arg1_arg_num, total_num_args);
1848+
ZSTR_VAL(func), arg1_arg_num, total_num_args);
1849+
zend_string_release(func);
18341850
return false;
18351851
}
18361852
if (Z_TYPE_P(arg1) != IS_OBJECT) {
@@ -1886,7 +1902,7 @@ PHP_METHOD(PDOStatement, setFetchMode)
18861902

18871903
/* {{{ Advances to the next rowset in a multi-rowset statement handle. Returns true if it succeeded, false otherwise */
18881904

1889-
static int pdo_stmt_do_next_rowset(pdo_stmt_t *stmt)
1905+
static bool pdo_stmt_do_next_rowset(pdo_stmt_t *stmt)
18901906
{
18911907
/* un-describe */
18921908
if (stmt->columns) {

0 commit comments

Comments
 (0)