You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "lord (via GitHub)" <gi...@apache.org> on 2023/06/13 16:03:36 UTC

[GitHub] [arrow] lord opened a new issue, #36050: C producer examples leak memory?

lord opened a new issue, #36050:
URL: https://github.com/apache/arrow/issues/36050

   ### Describe the usage question you have. Please include as many useful details as  possible.
   
   
   Perhaps my limited C knowledge is making me miss something obvious, but I think the producer examples on [this page](https://arrow.apache.org/docs/format/CDataInterface.html#exporting-a-struct-float32-utf8-array) of the documentation leak memory? Child schemas are malloced:
   
   ```c
    //
    // Initialize child type #0
    //
    child = schema->children[0] = malloc(sizeof(struct ArrowSchema));
   ```
   
   Then in the release implementation, we free the array of child pointers and call release on the children array, but don't actually free the child ArrowSchema allocations:
   
   ```c
   static void release_malloced_type(struct ArrowSchema* schema) {
      int i;
      for (i = 0; i < schema->n_children; ++i) {
         struct ArrowSchema* child = schema->children[i];
         if (child->release != NULL) {
            child->release(child);
         }
      }
      free(schema->children);
      // Mark released
      schema->release = NULL;
   }
   ```
   
   Since (as far as I can tell?) the docs don't otherwise explicitly state what the lifetime of these children is, it could be nice to fix this? Reading the C++ ExportArray implementation, it seems like these are in fact freed in the release call via the private_data pointer in at least the C++ implementation.
   
   ### Component(s)
   
   C, Documentation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] zeroshade commented on issue #36050: C producer examples leak memory?

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #36050:
URL: https://github.com/apache/arrow/issues/36050#issuecomment-1589620651

   The docs specify the lifetime and memory management semantics here: https://arrow.apache.org/docs/format/CDataInterface.html#memory-management
   
   That said, it looks like you're right. There should be a `free(child);` after `child->release(child);` Would you be willing to contribute a PR to fix it? :smile:
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] kou closed issue #36050: [Docs] C producer examples leak memory?

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou closed issue #36050: [Docs] C producer examples leak memory?
URL: https://github.com/apache/arrow/issues/36050


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org