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

lazyLoop->free() causes leak/crash #53

Closed
Dysl3xik opened this issue May 7, 2019 · 1 comment
Closed

lazyLoop->free() causes leak/crash #53

Dysl3xik opened this issue May 7, 2019 · 1 comment

Comments

@Dysl3xik
Copy link

Dysl3xik commented May 7, 2019

FYI: I am using uWS in visual studio in a windows environment.

I was able to dig through issues and find how to stop listening so that the event loop can finish its work and attempt to exit. Ultimately leading to the application exiting.

For me, when the loop was trying to free its self using Loop::get()->free() it was actually causing another loop to be spawned (the call to get() didn't return the previously instantiated loop), then when trying to free the SECOND loop things went haywire.

Apparently the thead context for std::atexit is not as you expected in windows OS.

Anyways its a (seemingly) easy fix, remove the call to Loop::get() in the atexit lambda:

static Loop *get(void *existingNativeLoop = nullptr) {
	static thread_local Loop *lazyLoop = nullptr;
	if (!lazyLoop) {
		/* If we are given a native loop pointer we pass that to uSockets and let it deal with it */
		if (existingNativeLoop) {
			/* Todo: here we want to pass the pointer, not a boolean */
			lazyLoop = create(true);
			/* We cannot register automatic free here, must be manually done */
		} else {
			lazyLoop = create(false);
			std::atexit([]() {
					 if(lazyLoop)
						lazyLoop->free();
			});
		}
	}

	return lazyLoop;
}
@Dysl3xik
Copy link
Author

Dysl3xik commented May 7, 2019

Oops I intended to post this in uWS C++! Will close and migrate to there!

@Dysl3xik Dysl3xik closed this as completed May 7, 2019
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

1 participant