Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-294

document or change memory allocations in C API completion handling


    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.0, 3.0.1, 3.1.0
    • Fix Version/s: None
    • Component/s: c client
    • Labels:


      The C API zookeeper_process() function, which is used in the IO thread, generally copies data into memory locations provided by the caller (for example, when handling a string completion, it uses memcpy() to copy the string data into a user-provided buffer).

      However, when handling string-list and ACL-list completions, memory is allocated by deserialize_GetChildrenResponse() and deserialize_GetACLResponse(), respectively, but not released afterward. Instead it is passed back to the user. This implies the user is responsible for calling deallocate_GetChildrenResponse() or deallocate_GetACLResponse(), respectively.

      At a minimum, this needs to be extremely well-documented.

      Perhaps better, the user should be able to pass an allocation function and a parameter to be passed to it. Then this function can called repeatedly as a callback in order to allocate the necessary memory. However, this does assume that the user's allocation function is MT-safe; that requirement would need to be documented if this approach is taken.

      For example, when using the ZooKeeper C API with the Apache Portable Runtime, one would ideally be able to use APR memory pools for such allocation requests. To do that, the user could pass a wrapper function for apr_palloc() and a data parameter that included a private sub-pool. The sub-pool would be MT-safe so long as it is used exclusively by the IO thread.

      So, something like zoo_get_children(..., zoo_alloc_func *alloc_func, void *alloc_data). This would obviously be a change most appropriate for a major version release, e.g., 4.0.0.




            • Assignee:
              cdarroch Chris Darroch
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: