Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Have detach() check for store validity first.

  • Loading branch information...
commit 75c9bc82708a6245a3aec2a2b55652afbd5611af 1 parent 2c4b3ba
@colder authored
Showing with 21 additions and 14 deletions.
  1. +21 −14 php_weakref.c
View
35 php_weakref.c
@@ -120,24 +120,31 @@ void wr_store_detach(zend_object *intern, zend_object_handle ref_handle TSRMLS_D
{
wr_store *store = WR_G(store);
- wr_store_data *data = &store->objs[ref_handle];
- wr_ref_list *prev = NULL;
- wr_ref_list *cur = data->wrefs_head;
+ if (!store) {
+ // detach() can be called after the store has already been cleaned up,
+ // depending on the shutdown sequence (i.e. in case of a fatal).
+ // See tests/weakref_007.phpt
+ return;
+ } else {
+ wr_store_data *data = &store->objs[ref_handle];
+ wr_ref_list *prev = NULL;
+ wr_ref_list *cur = data->wrefs_head;
- while (cur && cur->obj != intern) {
- prev = cur;
- cur = cur->next;
- }
+ while (cur && cur->obj != intern) {
+ prev = cur;
+ cur = cur->next;
+ }
- assert(cur != NULL);
+ assert(cur != NULL);
- if (prev) {
- prev->next = cur->next;
- } else {
- data->wrefs_head = cur->next;
- }
+ if (prev) {
+ prev->next = cur->next;
+ } else {
+ data->wrefs_head = cur->next;
+ }
- efree(cur);
+ efree(cur);
+ }
}
/* }}} */
Please sign in to comment.
Something went wrong with that request. Please try again.