Skip to content

Commit

Permalink
handle deallocation request in native_resolve_cb
Browse files Browse the repository at this point in the history
When librdkafka calls the resolve callback with all pointers set to null
pointers it is a signal that the callback should deallocate the provided
addrinfo.

Signed-off-by: Petros Angelatos <[email protected]>
Co-authored-by: Nikhil Benesch <[email protected]>
  • Loading branch information
petrosagg and benesch committed Jan 30, 2024
1 parent 6e957d5 commit 8b419f8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ pub(crate) unsafe extern "C" fn native_resolve_cb<C: ClientContext>(
res: *mut *mut addrinfo,
opaque: *mut c_void,
) -> i32 {
if node.is_null() {
// If `node`` is `NULL`, we expect `service` and `hints` to also be
// `NULL`, and altogether this indicates a request to free `res`.
assert!(service.is_null());
assert!(hints.is_null());
unsafe { libc::freeaddrinfo(*res) }
return 0; // NOTE: this return code is ignored by librdkafka in this code path
}

// Convert host and port to Rust strings.
let host = match CStr::from_ptr(node).to_str() {
Ok(host) => host.into(),
Expand Down

0 comments on commit 8b419f8

Please sign in to comment.