Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1737

Use zend_hash_graceful_reverse_destroy to free persistent client HashTable

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.10.0-alpha1, 1.10.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      We currently use ZEND_HASH_REVERSE_FOREACH to free persistent clients. We should be able to simplify this code to just use zend_hash_graceful_reverse_destroy, provided we also designate an element destructor.

      Quoting the PHP 5 HashTable docs (since PHP 7+ version is unwritten):

      The zend_hash_destroy() function will invoke the destructor function on all buckets and free them. While this function runs the hashtable is in an inconsistent state and can not be used. This is usually okay, but in some rare cases (especially if the destructor function can call userland code) it may be necessary that the hashtable stays usable during the destruction process. In this case the zend_hash_graceful_destroy() and zend_hash_graceful_reverse_destroy() functions can be used. The former function will destroy the buckets in order of insertion, the latter in reverse order.

      There is no zend_hash_reverse_destroy, so we should use zend_hash_graceful_reverse_destroy. Coincidentally, this is the same function PHP uses to destroy loaded modules (which may depend on previously loaded modules).

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: