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

fixes potential memory leak in ccn-lite-ctrl.c #341

Merged
merged 2 commits into from
Jan 31, 2019

Conversation

mfrey
Copy link
Collaborator

@mfrey mfrey commented Jan 30, 2019

Contribution description

The PR checks if a call to strdup failed and also introduces a new variable which stores the newly allocated memory before it is overwritten again by a call to strtok and thus, the memory allocated by strdup can't be freed anymore.

Issues/PRs references

Fixes #327

@mfrey mfrey added the minor label Jan 30, 2019
@mfrey mfrey changed the title addresses potential memory leak in ccn-lite-ctrl.c fixes potential memory leak in ccn-lite-ctrl.c Jan 30, 2019
port = strtol(strtok(NULL, "/"), NULL, 0);
use_udp = 1;
printf("udp: <%s> <%i>\n", udp, port);

/** if memory has been allocated previously, free it */
if (udp_temp) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't udp_temp always non-NULL here? Is this check necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

If Malloc returns NULL in strdup because system is out of memory it can be NULL

Copy link
Collaborator

Choose a reason for hiding this comment

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

But there is a check for that only 9 lines above ..

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. Missed that. So, we can remove that.

Copy link
Contributor

@blacksheeep blacksheeep left a comment

Choose a reason for hiding this comment

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

Remove unnecessary check, see comments

@mfrey
Copy link
Collaborator Author

mfrey commented Jan 31, 2019

Remove unnecessary check, see comments

Has been addressed with the latest updated commit (rebased, push -f)

@blacksheeep Could you please approve the PR?

@mfrey mfrey merged commit fb45107 into cn-uofbasel:master Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants