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
JDK-8260432: allocateSpaceForGP in freetypeScaler.c might leak memory #2250
Conversation
👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into |
Webrevs
|
@@ -1285,7 +1287,7 @@ static int allocateSpaceForGP(GPData* gpdata, int npoints, int ncontours) { | |||
} | |||
|
|||
/* failure if any of mallocs failed */ | |||
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) | |||
if (gpdata->pointTypes == NULL || gpdata->pointCoords == 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 think it would be cleaner to free the remaining allocations on the failing path:
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) {
if (gpdata->pointTypes != NULL) free(gpdata->pointTypes);
if (gpdata->pointCoords != NULL) free(gpdata->pointCoords);
return 0;
} else {
return 1;
}
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.
Then we would free as well for the realloc code path
} else {
/* do we have enough space? */
...
}
Is this okay?
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.
Yes, I think that is better: realloc
can fail as well, and we don't want to leak those?
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.
Please also reset the free'd pointers to NULL in GPData* before returning.
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.
Hello Thomas and Aleksey, I moved the free calls and added the NULL settings. Are you fine with the latest commit?
Thanks, Matthias
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.
This looks fine to me, modulo stylistic nits
@@ -1285,10 +1285,12 @@ static int allocateSpaceForGP(GPData* gpdata, int npoints, int ncontours) { | |||
} | |||
|
|||
/* failure if any of mallocs failed */ | |||
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) | |||
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) { | |||
if (gpdata->pointTypes != NULL) { free(gpdata->pointTypes); gpdata->pointTypes = 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.
You might want to add an extra space before gpdata->pointTypes = NULL;
to align the statements vertically. You call.
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.
Can we also style it consistently, like:
if (gpdata->pointTypes != NULL) {
free(gpdata->pointTypes);
gpdata->pointTypes = NULL;
}
if (gpdata->pointCoords != NULL) {
free(gpdata->pointCoords);
gpdata->pointCoords = NULL;
}
Pull from master to get x86_32 GHA jobs fixed and running. |
@MBaesken This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 23 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
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.
Hi Matthias,
looks fine. See remark below, but that is just nitpicking, this is fine as it is.
Cheers, Thomas
if (gpdata->pointCoords != NULL) { | ||
free(gpdata->pointCoords); | ||
gpdata->pointCoords = NULL; | ||
} | ||
return 0; |
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.
If you wanted, you could streamline this to:
if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) {
free(gpdata->pointTypes);
free(gpdata->pointCoords);
gpdata->pointTypes = gpdata->pointCoords = NULL;
return 0;
Since free(NULL) is valid and a noop.
/integrate |
@MBaesken Since your change was applied there have been 35 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 3aabbd7. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The function AllocateSpaceForGP in freetypeScaler.c calls potentially 2 times malloc ; however the memory is not always freed correctly in case of errors.
See also the related sonar issue :
https://sonarcloud.io/project/issues?id=shipilev_jdk&languages=c&open=AXck8B_SBBG2CXpcngxr&resolved=false&severities=BLOCKER&types=BUG
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2250/head:pull/2250
$ git checkout pull/2250