Skip to content

Fix #143: memory leak from not freeing per-message callback pointer #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2020

Conversation

felixmulder
Copy link
Contributor

No description provided.

-- Here we fork the callback since it might be a longer action and
-- blocking here would block librdkafka from continuing its execution
void . forkIO $ msgCb rep
freeStablePtr stablePtr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would bracket be better in this situation?
Or it doesn't matter in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice, but I don't think it's possible. The pointer is created in Kafka.Producer and when the per-message callback is invoked it ends up here. So there's not really a good way to tie those two together that I can think of...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of bracket (castPtrToStablePtr cbPtr) freeStablePtr $ \stablePrt -> do ..., not the actual pointer...

Copy link
Contributor Author

@felixmulder felixmulder May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to do:

else bracket (pure $ castPtrToStablePtr cbPtr) freeStablePtr $ \stablePtr -> do
  msgCb <- deRefStablePtr @(DeliveryReport -> IO ()) stablePtr
  -- Here we fork the callback since it might be a longer action and
  -- blocking here would block librdkafka from continuing its execution
  void . forkIO $ msgCb rep

I can change it to that if ya like :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@felixmulder felixmulder force-pushed the free-ptr-after-use branch from d91944a to f173cc5 Compare May 20, 2020 12:15
@AlexeyRaga
Copy link
Member

Thank you very much!

@AlexeyRaga AlexeyRaga merged commit f7fad14 into haskell-works:master May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants