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 with mock #325

Closed
namrog84 opened this issue Oct 30, 2018 · 2 comments
Closed

Double free with mock #325

namrog84 opened this issue Oct 30, 2018 · 2 comments

Comments

@namrog84
Copy link
Contributor

namrog84 commented Oct 30, 2018

Since we had written our own thread scheduler to consume the task. We recently started some seeing unusual results.

I started with a ExampleSingleGenericMock from https://github.com/Microsoft/libHttpClient/blob/master/Tests/UnitTests/Tests/MockTests.cpp

In the same unit test,
VERIFY_ARE_EQUAL(S_OK, HCHttpCallCloseHandle(call));
HCCleanup();
are both called but inside HCCleanup is where the http_singleton is destroyed

https://github.com/Microsoft/libHttpClient/blob/e7726a89b99b715287469e2651b9b7bff9692797/Source/Global/global.cpp#L45

HCHttpCallCloseHandle(mockCall); is called on all the mock calls.

So HCHttpCallCloseHandle is being called both by the unit test AND in the httpsingleton cleanup.

This caused some unusual behavior.

We ultimately were hitting this assert. Since it had been free'd earlier, it now contained garbage data (e.g. if (refCount was equal to like -2384234)
https://github.com/Microsoft/libHttpClient/blob/1d749c20bd522d056f339e18b01d8df70e132482/Source/HTTP/httpcall.cpp#L84

Proposed solutions:

  • Remove CallCloseHandle for mocks in the cleanup, and make it behave like non mock, where the user is responsible for cleaning it up.
  • Add additional ref counting to the mocks, so that there isn't a double free scenario.

Let me know if you need additional information and clarity.

@jasonsandlin
Copy link
Member

Feel free to submit a PR to fix it. Sounds like making it behave like a non-mock is the best choice.

@namrog84
Copy link
Contributor Author

I believe the issue might have been originating from the use of 2 httpcalls in the example. One to setup the fake response and 1 to setup the actual call.

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