CPP: Handle 'realloc' better in MemoryMayNotBeFreed.ql#114
Merged
Conversation
jbj
previously approved these changes
Aug 30, 2018
3a220f5 to
f44d708
Compare
f44d708 to
8e5c170
Compare
Contributor
|
@geoffw0 this is for 1.18, right? I've put the 1.18 milestone on it, and I've retargeted the PR to the |
Contributor
|
I think my retargeting of the PR and my triggering of Language-Tests/CPP got a bit racy and that Jenkins is now testing |
Contributor
Author
I had been hoping so, yes. |
Contributor
|
The test failed because (I think) this repo's |
Contributor
|
The only test failures now are the ones that will be fixed by the internal PR, so I'm merging both now. |
jbj
approved these changes
Sep 5, 2018
Merged
aibaars
added a commit
that referenced
this pull request
Oct 14, 2021
Correct the scope of class/method names etc.
smowton
pushed a commit
to smowton/codeql
that referenced
this pull request
Dec 6, 2021
…names-and-usetype Merge shortName recursion into useType
erik-krogh
pushed a commit
to erik-krogh/ql
that referenced
this pull request
Dec 15, 2021
fix the signature of regexpCapture and regexpFind
erik-krogh
pushed a commit
to erik-krogh/ql
that referenced
this pull request
Dec 15, 2021
fix the signature of regexpCapture and regexpFind
MathiasVP
added a commit
to MathiasVP/ql
that referenced
this pull request
Aug 10, 2025
PS: Support flow through `this`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
MemoryMayNotBeFreed.qlquery normally considers areallocto be both analloc, and afreeof the old pointer. A subtlety is that ifreallocfails and returnsNULLit does not free the old pointer. To account for this the query considers the free of the old pointer to occur only if and when the return value is checked:This works well up until we assign to the same variable:
Because now we get confused by the old vs new
ptr_aand think the new allocation is being freed.The ideal solution is probably to upgrade this query to use something like
DataFlowrather thanLocalScopeVariableReachability(I've created a JIRA ticket for this).However, we need a quick fix because it's causing a regression on version 1.3 of the samate test-suite compared to the results we had on version 1.2. The workaround is not to consider this particular pattern on
reallocas to be a free at all.