php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61929 Possible bug in ts_resource_ex of TSRM.c
Submitted: 2012-05-03 20:09 UTC Modified: 2012-05-05 01:41 UTC
From: drueter at assyst dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.2 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: drueter at assyst dot com
New email:
PHP Version: OS:

 

 [2012-05-03 20:09 UTC] drueter at assyst dot com
Description:
------------
While reviewing source code for both 5.4.2 and 5.3.12 I noticed what looks like a bug in the implementation of ts_resource_ex in TSRM.c

I have not experienced a problem, but from the code it looks like there is a condition in which a mutex will be locked and never unlocked.

In TSRM.c within the implementation of ts_resource_ex, starting about line 345 I see the following:

tsrm_mutex_lock(tsmm_mutex);
...
else {
  allocate_new_resource(&thread_resources->next, thread_id);
  return ts_resource_ex(id, &thread_id);
  /*
   * thread_resources = thread_resources->next;
   * break;
   */
...			}
tsrm_mutex_unlock(tsmm_mutex);

I think the "break" in the old code that has been commented out is correct, and the "return" in the new code is uncorrect.  I think that in the event this branch of execution be taken, the tsmm_mutex will be locked but will never be unlocked.

Alternatively, if the thinking was that the recursive call to ts_resource_ex would unlock the mutex, I think there is still a problem because in this case the mutex would be locked twice, but unlocked only once.

Finally, if somehow the code is correct as it stands, it is sufficiently confusing that a comment should be added.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-04 07:43 UTC] laruence@php.net
the mutex also be unlocked in allocate_new_resource. however I am not sure whether 
I got your idea..
 [2012-05-05 01:41 UTC] felipe@php.net
As Laruence stated, the allocate_new_resource() function does the unlock job.
 [2012-05-05 01:41 UTC] felipe@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 13 15:00:03 2025 UTC