Skip to content

Commit 2311ba7

Browse files
committed
Fix bug #66283 (Segmentation fault after memory_limit)
There are situations where mysqlnd dupliates zvals while freeing result sets. If the memory_limit is reached during this operation the engine will bailout. This patch makes sure that a later attempt (during RSHIUTDOWN) won't cause a double free, instead we rely on the engine to free emalloc()ed memory after bailout.
1 parent 2bd68bf commit 2311ba7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug #66286 (Incorrect object comparison with inheritance). (Nikita)
77
. Fixed bug #66509 (copy() arginfo has changed starting from 5.4). (willfitch)
88

9+
- mysqlnd
10+
. Fixed bug #66283 (Segmentation fault after memory_limit). (Johannes)
11+
912
- PDO_pgsql:
1013
. Fixed bug #62479 (PDO-psql cannot connect if password contains spaces) (willfitch, iliaa)
1114

ext/mysqlnd/mysqlnd_result.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES * result TSRMLS_DC)
198198
if (set->data) {
199199
unsigned int copy_on_write_performed = 0;
200200
unsigned int copy_on_write_saved = 0;
201+
zval **data = set->data;
202+
set->data = NULL; /* prevent double free if following loop is interrupted */
201203

202204
for (row = set->row_count - 1; row >= 0; row--) {
203-
zval **current_row = set->data + row * field_count;
205+
zval **current_row = data + row * field_count;
204206
MYSQLND_MEMORY_POOL_CHUNK *current_buffer = set->row_buffers[row];
205207
int64_t col;
206208

@@ -222,8 +224,7 @@ MYSQLND_METHOD(mysqlnd_res, free_buffered_data)(MYSQLND_RES * result TSRMLS_DC)
222224

223225
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_COPY_ON_WRITE_PERFORMED, copy_on_write_performed,
224226
STAT_COPY_ON_WRITE_SAVED, copy_on_write_saved);
225-
mnd_efree(set->data);
226-
set->data = NULL;
227+
mnd_efree(data);
227228
}
228229

229230
if (set->row_buffers) {

0 commit comments

Comments
 (0)