Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid leaking memory when deallocating libjudy Judy Hash Set (JudyHS) data structures using the JSHFA() macro?
    primarykey
    data
    text
    <p>I want to use libjudy to build some data structures to store information keyed on fixed length byte arrays, which means that I need to use the JudyHS structures. Based on my understanding of the code and the documentation, a key will only be able to access an element consisting of a single machine word, which would be fine since I want to save a pointer to a struct allocated on the heap; however, there is a problem in that there appears to be no way to iterate over the previously stored elements, and the macro used to deallocate the structure (JHSFA), calls free() on the memory used to store the word of data, but provides no mechanism to allow the calling code to deallocate memory that the word points to. I verified that JHSFA doesn't deallocate user supplied memory using valgrind and the following example code:</p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;judy.h&gt; int main( const int argc, const char *argv[] ) { Pvoid_t table = (PWord_t)NULL; const size_t allocSize = sizeof("bar") + 1; char *bar = calloc(1, allocSize); strncpy(bar, "bar", allocSize); uint64_t key = UINT32_MAX + 1; PWord_t entry; JHSI(entry, table, &amp;key, sizeof(key)); *entry = (Word_t)bar; entry = NULL; JHSG(entry, table, &amp;key, sizeof(key)); if (!strncmp(bar, (const char *)(*entry), allocSize)) { printf("match\n"); } else { printf("no match\n"); } Word_t result; JHSFA(result, table); } </code></pre> <p>Given that this is the case, can some other libjudy user out there point me to a way to avoid a memory leak if this data structure is the only place where I store the data?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload