intel / openvino-rs

Rust bindings for OpenVINO™
Apache License 2.0
80 stars 23 forks source link

Fix cstr macro leak #123

Closed pnehrer closed 2 months ago

pnehrer commented 2 months ago

The cstr macro uses CString::into_raw() to get the c-compatible string pointer.

However, per Rust doc, into_raw actually leaks the pointer if it isn't reclaimed and deallocated using from_raw.

This PR changes the macro and its usage to:

  1. Create a CString
  2. Keep it alive as we take its pointer (as_ptr)
  3. Pass its as_ptr to the c functions