Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f9dfd9

Browse files
committed
Fix bug #77955
Free metadata before freeing the arena. I don't have a repro script, but the added assertion fails for many existing tests prior to this change.
1 parent b394654 commit 6f9dfd9

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug #77956 (When mysqli.allow_local_infile = Off, use a meaningful
1515
error message). (Sjon Hortensius)
1616

17+
- MySQLnd:
18+
. Fixed bug #77955 (Random segmentation fault in mysqlnd from php-fpm).
19+
(Nikita)
20+
1721
- Opcache:
1822
. Fixed bug #78015 (Incorrect evaluation of expressions involving partials
1923
arrays in SCCP). (Nikita)

Zend/zend_arena.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ static zend_always_inline void zend_arena_release(zend_arena **arena_ptr, void *
110110
arena->ptr = (char*)checkpoint;
111111
}
112112

113+
static zend_always_inline zend_bool zend_arena_contains(zend_arena *arena, void *ptr)
114+
{
115+
while (arena) {
116+
if ((char*)ptr > (char*)arena && (char*)ptr <= arena->ptr) {
117+
return 1;
118+
}
119+
arena = arena->prev;
120+
}
121+
return 0;
122+
}
123+
113124
#endif /* _ZEND_ARENA_H_ */
114125

115126
/*

ext/mysqlnd/mysqlnd_result.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,14 @@ void MYSQLND_METHOD(mysqlnd_res, free_result_contents_internal)(MYSQLND_RES * re
294294
{
295295
DBG_ENTER("mysqlnd_res::free_result_contents_internal");
296296

297-
result->m.free_result_buffers(result);
298-
299297
if (result->meta) {
298+
ZEND_ASSERT(zend_arena_contains(result->memory_pool->arena, result->meta));
300299
result->meta->m->free_metadata(result->meta);
301300
result->meta = NULL;
302301
}
303302

303+
result->m.free_result_buffers(result);
304+
304305
DBG_VOID_RETURN;
305306
}
306307
/* }}} */

0 commit comments

Comments
 (0)