Skip to content

Commit 4eceb60

Browse files
committed
mysqlnd: Make st_mysqlnd_stats.values a dynamic struct member
This avoids another separate allocation.
1 parent 8c266e8 commit 4eceb60

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

ext/mysqlnd/mysqlnd_statistics.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING
214214
PHPAPI void
215215
mysqlnd_stats_init(MYSQLND_STATS ** stats, const size_t statistic_count, const bool persistent)
216216
{
217-
*stats = pecalloc(1, sizeof(MYSQLND_STATS), persistent);
218-
(*stats)->values = pecalloc(statistic_count, sizeof(uint64_t), persistent);
217+
size_t size = zend_safe_address_guarded(statistic_count, sizeof(*(*stats)->values), sizeof(**stats));
218+
*stats = pecalloc(1, size, persistent);
219219
(*stats)->count = statistic_count;
220220
#ifdef ZTS
221221
(*stats)->LOCK_access = tsrm_mutex_alloc();
@@ -231,7 +231,6 @@ mysqlnd_stats_end(MYSQLND_STATS * stats, const bool persistent)
231231
#ifdef ZTS
232232
tsrm_mutex_free(stats->LOCK_access);
233233
#endif
234-
pefree(stats->values, persistent);
235234
/* mnd_free will reference LOCK_access and crash...*/
236235
pefree(stats, persistent);
237236
}

ext/mysqlnd/mysqlnd_structs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ typedef struct st_mysqlnd_stats MYSQLND_STATS;
297297

298298
struct st_mysqlnd_stats
299299
{
300-
uint64_t *values;
301300
size_t count;
302301
#ifdef ZTS
303302
MUTEX_T LOCK_access;
304303
#endif
304+
uint64_t values[] ZEND_ELEMENT_COUNT(count);
305305
};
306306

307307

0 commit comments

Comments
 (0)