Skip to content

Comments

fix common realloc mistake in custom_output_search_replace.c#931

Merged
ddpbsd merged 1 commit intoossec:masterfrom
bryonglodencissp:patch-3
Sep 27, 2016
Merged

fix common realloc mistake in custom_output_search_replace.c#931
ddpbsd merged 1 commit intoossec:masterfrom
bryonglodencissp:patch-3

Conversation

@bryonglodencissp
Copy link

Passing one pointer into realloc() and assigning the result directly into that same pointer variable can cause a memory leak if the reallocation fails, because the original allocation will still exist. The correct way to do this is to use a temporary pointer variable.

Found by https://github.com/bryongloden/cppcheck

[src/shared/custom_output_search_replace.c:39]: (error) Common realloc mistake: 'tmp' nulled but not freed upon failure
[src/shared/custom_output_search_replace.c:52]: (error) Common realloc mistake: 'tmp' nulled but not freed upon failure
[src/shared/custom_output_search_replace.c:67]: (error) Common realloc mistake: 'tmp' nulled but not freed upon failure
@ddpbsd ddpbsd merged commit 80d1262 into ossec:master Sep 27, 2016
@ddpbsd
Copy link
Member

ddpbsd commented Sep 27, 2016

Thanks for the patch!

@vikman90 vikman90 mentioned this pull request Dec 21, 2016
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.

2 participants