Skip to content

Memory leak when using CloseCallback for HeaderClientChannel #40

Closed

Description

@swxlion

Class HeaderClientChannel has a method to set CloseCallback when connection closed, which requires a naked pointer. The callback will be called in asynchronously. By normal thought, in this case, for an asynchronous callback object, developer will new a callback object, then pass the naked pointer to then function, and hope class HeaderClientChannel take the ownership, and free the callback object if necessary.
But I found in the HeaderClientChannel class, in the function
void HeaderClientChannel::messageChannelEOF(),
after called closeCallback_->channelClosed(), then, the class assigns nullptr to the pointer:
closeCallback_ = nullptr;

In this case, memory leaking is occurred.
But I think in the asynchronous case, developer haven't the responsibility to holder a callback and free them.
And no any note to say, need to delete this in the function channelClosed().

Activity

  1. djwatson commented on Oct 30, 2014

    @djwatson

    This was by design - in practice we found that we are often setting/unsetting the close callback in our connection pooling implementation based on some parameters. We want to be able to control the lifetime of the close callback outside of the headerclientchannel itself.

    Definitely we could update the docs for this, users can always do a 'delete this' in channelClosed

  2. swxlion commented on Oct 31, 2014

    @swxlion
    Author

    OK, please update the docs to tell users what them ought to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions