-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Fix potential Null pointer dereference in test-fdleak.c #1610
base: master
Are you sure you want to change the base?
Conversation
@@ -111,6 +111,9 @@ listener_accept_cb(struct evconnlistener *listener, evutil_socket_t sock, | |||
struct event_base *base = evconnlistener_get_base(listener); | |||
struct bufferevent *bev = bufferevent_socket_new(base, sock, | |||
BEV_OPT_CLOSE_ON_FREE); | |||
if (bev == NULL) { | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fd leaked here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll fix it
@@ -209,6 +212,10 @@ start_client(struct event_base *base) | |||
{ | |||
struct bufferevent *bev = bufferevent_socket_new(base, -1, | |||
BEV_OPT_CLOSE_ON_FREE); | |||
if (bev == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish that the main
would have a normal error path, i.e.:
if (!start_client)
goto cleanup;
...
cleanup:
if (listener)
evconnlistener_free(listener);
if (base)
event_base_free(base);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the example
I previously misunderstood; while modifying the code, I noticed that I hadn't altered the main function, so perhaps adding a cleanup path is unnecessary? Also, regarding the 'fd leaked' issue, there seems to be no file descriptor here. I believe there are no newly allocated variables within this function, thus no need for cleanup. If I've overlooked something, please highlight it for me. |
You didn't, but you modified start_client, and main calls it (start_loop -> start_client), so if it can fail it should propagate error to main, since the whole point of this PR to make avoid any leaks on exit AFAIU
|
Perhaps I should handle the cleanup in |
This is OK
Yes, you should not call |
No description provided.