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

net.c: memory leak in handle_request if error input #536

Merged
merged 1 commit into from
Aug 12, 2020

Conversation

mrdeep1
Copy link
Collaborator

@mrdeep1 mrdeep1 commented Aug 7, 2020

coap_add_token() can error for multiple reasons when building the response
PDU - but then the response PDU is not deleted on error if it exists.

The PDU is now deleted on coap_add_token() error.

Fixes #535

@mrdeep1
Copy link
Collaborator Author

mrdeep1 commented Aug 7, 2020

Build fails - needs #532

src/net.c Outdated
@@ -2366,6 +2366,10 @@ handle_request(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu
response = NULL;
} else {
coap_log(LOG_WARNING, "cannot generate response\r\n");
if (response) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delete functions in libcoap are all designed to be callable with a NULL argument, analogous to free(). Therefore, we can do without the extra check here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code updated and pushed.

coap_add_token() can error for multiple reasons when building the response
PDU - but then the response PDU is not deleted on error if it exists.

The PDU is now deleted on coap_add_token() error.
@obgm obgm merged commit 1739507 into obgm:develop Aug 12, 2020
@mrdeep1 mrdeep1 deleted the bad_tcp branch August 12, 2020 16:01
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

Successfully merging this pull request may close these issues.

Memory leak at handle_request
2 participants