Skip to content

Commit 097c927

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Move locks in TSRM.c to prevent races
2 parents e3a5e42 + 1a75269 commit 097c927

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug GH-8310 (Registry settings are no longer recognized). (cmb)
7+
. Fixed potential race condition during resource ID allocation. (ryancaicse)
78

89
- Date:
910
. Fixed bug GH-7752 (DateTimeZone::getTransitions() returns insufficient

TSRM/TSRM.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate
288288
tsrm_resource_type *_tmp;
289289
_tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
290290
if (!_tmp) {
291-
tsrm_mutex_unlock(tsmm_mutex);
292291
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
293292
*rsrc_id = 0;
293+
tsrm_mutex_unlock(tsmm_mutex);
294294
return 0;
295295
}
296296
resource_types_table = _tmp;
@@ -331,10 +331,10 @@ TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, siz
331331

332332
size = TSRM_ALIGNED_SIZE(size);
333333
if (tsrm_reserved_size - tsrm_reserved_pos < size) {
334-
tsrm_mutex_unlock(tsmm_mutex);
335334
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate space for fast resource"));
336335
*rsrc_id = 0;
337336
*offset = 0;
337+
tsrm_mutex_unlock(tsmm_mutex);
338338
return 0;
339339
}
340340

@@ -346,9 +346,9 @@ TSRM_API ts_rsrc_id ts_allocate_fast_id(ts_rsrc_id *rsrc_id, size_t *offset, siz
346346
tsrm_resource_type *_tmp;
347347
_tmp = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
348348
if (!_tmp) {
349-
tsrm_mutex_unlock(tsmm_mutex);
350349
TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
351350
*rsrc_id = 0;
351+
tsrm_mutex_unlock(tsmm_mutex);
352352
return 0;
353353
}
354354
resource_types_table = _tmp;

0 commit comments

Comments
 (0)