Skip to content

Queue & Deque segfault upon GC #114

Closed
@orls

Description

@orls

Queue & Deque can segfault when GC is triggered:

<?php

$q = new \Ds\Queue();

for ($i = 0; $i < 100 ; $i++) {
    $q->push(123);
    gc_collect_cycles();
}

Observed on:

  • php 7.2.5 & ds 1.2.5, Mac & linux (via docker for mac);
  • php 7.1.14 & ds 1.2.3, Mac

Not observed on php 7.1.4 & ds 1.2.3 (using this docker image mentioned in another issue).

I can avoid this locally by altering php_ds_queue_get_gc as follows (and similarlyphp_ds_dueue_get_gc):

     ds_queue_t *queue = Z_DS_QUEUE_P(obj);

     *gc_data  = queue->deque->buffer;
-    *gc_count = (int) queue->deque->capacity;
+    *gc_count = (int) queue->deque->size;

     return NULL;
 }

...but I'm not confident that this is a proper fix, since the bug seems to indicate that the spare capacity in the buffer is mis-initialized. Perhaps something about the lower-level mem mgmt used by deque reallocation has changed in PHP?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions