Skip to content

Commit 58c41b3

Browse files
committed
fix leaks
1 parent 1245997 commit 58c41b3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ static void sqlite3result_clear_column_names_cache(php_sqlite3_result *result) {
20122012

20132013
PHP_METHOD(SQLite3Result, fetchAll)
20142014
{
2015-
int i;
2015+
int i, nb_cols;
20162016
bool done = false;
20172017
php_sqlite3_result *result_obj;
20182018
zval *object = ZEND_THIS;
@@ -2026,15 +2026,17 @@ PHP_METHOD(SQLite3Result, fetchAll)
20262026

20272027
SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)
20282028

2029-
result_obj->column_count = sqlite3_column_count(result_obj->stmt_obj->stmt);
2029+
nb_cols = sqlite3_column_count(result_obj->stmt_obj->stmt);
20302030
if (mode & PHP_SQLITE3_ASSOC) {
2031-
result_obj->column_names = emalloc(result_obj->column_count * sizeof(zend_string*));
2031+
sqlite3result_clear_column_names_cache(result_obj);
2032+
result_obj->column_names = emalloc(nb_cols * sizeof(zend_string*));
20322033

2033-
for (i = 0; i < result_obj->column_count; i++) {
2034+
for (i = 0; i < nb_cols; i++) {
20342035
const char *column = sqlite3_column_name(result_obj->stmt_obj->stmt, i);
20352036
result_obj->column_names[i] = zend_string_init(column, strlen(column), 0);
20362037
}
20372038
}
2039+
result_obj->column_count = nb_cols;
20382040
array_init(return_value);
20392041

20402042
while (!done) {

0 commit comments

Comments
 (0)