Skip to content
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

SetGlobalCallbacks incorrectly taking ownership of pointer #37607

Open
RReichert opened this issue Aug 30, 2024 · 0 comments
Open

SetGlobalCallbacks incorrectly taking ownership of pointer #37607

RReichert opened this issue Aug 30, 2024 · 0 comments

Comments

@RReichert
Copy link

What version of gRPC and what language are you using?

gRPC C++ v1.45.2

Bug exists currently in master branch as well.

What operating system (Linux, Windows,...) and version?

Linux Fedora 40

What runtime / compiler are you using (e.g. python version or version of gcc)

Clang version 18.1.6 (Fedora 18.1.6-3.fc40)

What did you do?

Passed a global instance of GlobalCallbacks into grpc::Server::SetGlobalCallbacks.

What did you expect to see?

I expected that the global instance of the GlobalCallbacks wouldn't have its deconstructed called twice.

What did you see instead?

Application segfault as we created a derived class from the GlobalCallbacks and the deconstructor alerted of a double deconstruction.

Issue is that the documentation and the implementation don't match. Documentation states (see here):

  /// Set the global callback object. Can only be called once per application.
  /// Does not take ownership of callbacks, and expects the pointed to object
  /// to be alive until all server objects in the process have been destroyed.
  /// The same \a GlobalCallbacks object will be used throughout the
  /// application and is shared among all \a Server objects.
  static void SetGlobalCallbacks(GlobalCallbacks* callbacks);

Issue is that it states that it "Does not take ownership of callbacks", however in the implementation (see here) it does indeed take ownership of the objects lifetime, which is why during deconstruction I noticed this double free behavior.

Simple fix is to remove the std::shared_ptr usage here.

Anything else we should know about your project / environment?

No.

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

No branches or pull requests

2 participants