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

Double Free of std::coroutine_handle #1

Closed
liuq opened this issue Apr 10, 2022 · 4 comments
Closed

Double Free of std::coroutine_handle #1

liuq opened this issue Apr 10, 2022 · 4 comments
Assignees

Comments

@liuq
Copy link

liuq commented Apr 10, 2022

Apparently, when using the value_event class the system incurs in a double free error when exiting the program (i.e., all processes have been stopped).

value_process(64525,0x100f6c580) malloc: *** error for object 0x600001844050: pointer being freed was not allocated

Unfortunately I cannot go too much in depth for debugging, but it seems that the error is related to the following destructor (and possibly to this phenomenon) in event.hpp:

 class data {
  public:
    ...
    /// Destructor.
    virtual ~data() {
      for (auto &handle : handles_) {
        handle.destroy();
      }
    }
}

A possible workaround might be to use a std::suspend_always instead of a std::suspend_never for the final_suspend method, however I am not able to understand the implications for the simulation.

My system is a MacOS 12.3.1 running on Arm M1 Pro. The code has been compiled with g++-11 (Homebrew GCC 11.2.0_3) 11.2.0.

@liuq
Copy link
Author

liuq commented Apr 11, 2022

Some further inspection: having tested also on Linux (with gdb, and compiling with g++-10) it seems that is the destruction of the vector of handles, i.e.

 std::vector<std::__n4861::coroutine_handle<void>,
  std::allocator<std::__n4861::coroutine_handle<void> > >::~vector

that raises the double free, which means that the handles were already destroyed earlier in the code flow.

In this case the system is a Linux Ubuntu 20.04 with g++ v. 10.3.0.

@liuq
Copy link
Author

liuq commented Apr 11, 2022

Eureka! I'll send a PullRequest... there was the call of the superclass desctructor of value_event that apparently is un-necessary (since the superclass/subclass destructors will always be called) and which raised the issue.

@fschuetz04
Copy link
Owner

Thanks for your investigation! Looking forward to the pull request.

@fschuetz04
Copy link
Owner

Sorry for not getting back to you sooner. Please see my comments on your PR #3 . A fix for this issue is in the main branch now, please test again and close this issue if the fix works for you. Thanks for your work!

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

No branches or pull requests

2 participants