Skip to content

Commit 1a75269

Browse files
ryancaicsecmb69
authored andcommitted
Move locks in TSRM.c to prevent races
Closes GH-8298.
1 parent 84c18f9 commit 1a75269

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PHP NEWS
2121
. Fixed bug GH-8070 (memory leak of internal function attribute hash).
2222
(Tim Düsterhus)
2323
. Fixed bug GH-8160 (ZTS support on Alpine is broken). (Michael Voříšek)
24+
. Fixed potential race condition during resource ID allocation. (ryancaicse)
2425

2526
- Filter:
2627
. Fixed signedness confusion in php_filter_validate_domain(). (cmb)

TSRM/TSRM.c

Lines changed: 3 additions & 3 deletions
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)