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

freed pointer used in multithread mode #646

Closed
mccoysc opened this issue Apr 14, 2016 · 5 comments
Closed

freed pointer used in multithread mode #646

mccoysc opened this issue Apr 14, 2016 · 5 comments
Assignees

Comments

@mccoysc
Copy link

mccoysc commented Apr 14, 2016

freed pointer used in multithread mode.

on line 4977:
mg_call(nc, (pd->endpoint_handler ? pd->endpoint_handler : nc->handler),
MG_EV_HTTP_PART_END, &mp);

may be pd have been freed in somewhere when mg_call called.

@mccoysc
Copy link
Author

mccoysc commented Apr 15, 2016

1

@rojer
Copy link
Collaborator

rojer commented Apr 15, 2016

it is a bug that any data race can occur. even in multi=threaded mode one connection is still supposed to only be accessed from only one thread. i'll take a look.

@mccoysc
Copy link
Author

mccoysc commented Apr 15, 2016

i'v found the key place:

at line 3889:
c[1]->listener = nc->listener;
c[1]->proto_handler = nc->proto_handler;
c[1]->proto_data = nc->proto_data;
c[1]->user_data = nc->user_data;

if in work thread,i set like this:
c->flags | =MG_F_SEND_AND_CLOSE;

and immediately the main thread found that the MG_F_SEND_AND_CLOSE is set,it will free the conn and the conn's proto_data.
but really,the proto_data is being used by work thread.

so,my resolve is add some code when create work thread:
c[1]->proto_data_destructor = nc->proto_data_destructor;
nc->proto_data = NULL;

@mccoysc
Copy link
Author

mccoysc commented Apr 15, 2016

and also add these code:

if (c[1]->prev)
{
c[1]->prev= c[1]->next;
}

if (c[1]->next)
{
c[1]->next->prev = c[1]->prev;
}

@alashkin
Copy link
Contributor

Please, check with latest version

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

3 participants