Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tree-wide: Do not manually check for NULL before calling free() #19063

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

Closed
TimWolla wants to merge 1 commit into php:master from TimWolla:free-null-check

Conversation

Copy link
Member

@TimWolla TimWolla commented Jul 7, 2025
edited
Loading

Changes performed with Coccinelle:

@@
expression e;
@@
- if (e) {
	efree(e);
- }
@@
expression e;
@@
- if (e) {
	efree(e);
	e = NULL;
- }
@@
expression e;
@@
- if (e) {
	free(e);
- }
@@
expression e;
@@
- if (e) {
	free(e);
	e = NULL;
- }
@@
expression e, e2;
@@
- if (e) {
	pefree(e, e2);
- }
@@
expression e, e2;
@@
- if (e) {
	pefree(e, e2);
	e = NULL;
- }

Changes performed with Coccinelle:
 @@
 expression e;
 @@
 - if (e) {
 	efree(e);
 - }
 @@
 expression e;
 @@
 - if (e) {
 	efree(e);
 	e = NULL;
 - }
 @@
 expression e;
 @@
 - if (e) {
 	free(e);
 - }
 @@
 expression e;
 @@
 - if (e) {
 	free(e);
 	e = NULL;
 - }
 @@
 expression e, e2;
 @@
 - if (e) {
 	pefree(e, e2);
 - }
 @@
 expression e, e2;
 @@
 - if (e) {
 	pefree(e, e2);
 	e = NULL;
 - }
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Minor CS nits but looks nice :)

Comment on lines +150 to 151
efree((*session)->a); \
(*session)->a = NULL; \
Copy link
Member

@Girgias Girgias Jul 7, 2025

Choose a reason for hiding this comment

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

Suggested change
efree((*session)->a); \
(*session)->a = NULL; \
efree((*session)->a); \
(*session)->a = NULL; \

Comment on lines +363 to +364
/* malloc was used to store value */
efree(dbuf);
Copy link
Member

@Girgias Girgias Jul 7, 2025

Choose a reason for hiding this comment

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

Suggested change
/* malloc was used to store value */
efree(dbuf);
/* malloc was used to store value */
efree(dbuf);

Comment on lines 1120 to 1122
efree(error);

}
Copy link
Member

@Girgias Girgias Jul 7, 2025

Choose a reason for hiding this comment

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

Suggested change
efree(error);
}
efree(error);
}

Copy link
Member

devnexen commented Jul 7, 2025

the title caught me :) so not just free but zendmm api flavors.

Copy link
Member Author

Unfortunately this one caused a +0.03% performance regression on the Symfony Benchmark: https://github.com/php/php-src/actions/runs/16120616513?pr=19063

Probably one (or more) of the commonly used structures has a pointer that is mostly NULL, leading to an avoidable call to free().

Nevertheless, I was happy that I could showcase what Coccinelle would be able to provide us and I'm happy to advice for other kinds of cleanups that folks might want to do 😃

@TimWolla TimWolla deleted the free-null-check branch July 10, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@Girgias Girgias Girgias left review comments

@dstogov dstogov Awaiting requested review from dstogov dstogov will be requested when the pull request is marked ready for review dstogov is a code owner

@arnaud-lb arnaud-lb Awaiting requested review from arnaud-lb arnaud-lb will be requested when the pull request is marked ready for review arnaud-lb is a code owner

@nielsdos nielsdos Awaiting requested review from nielsdos nielsdos will be requested when the pull request is marked ready for review nielsdos is a code owner

@bukka bukka Awaiting requested review from bukka bukka will be requested when the pull request is marked ready for review bukka is a code owner

@devnexen devnexen Awaiting requested review from devnexen devnexen will be requested when the pull request is marked ready for review devnexen is a code owner

@SakiTakamachi SakiTakamachi Awaiting requested review from SakiTakamachi SakiTakamachi will be requested when the pull request is marked ready for review SakiTakamachi is a code owner

@NattyNarwhal NattyNarwhal Awaiting requested review from NattyNarwhal NattyNarwhal will be requested when the pull request is marked ready for review NattyNarwhal is a code owner

@kamil-tekiela kamil-tekiela Awaiting requested review from kamil-tekiela kamil-tekiela will be requested when the pull request is marked ready for review kamil-tekiela is a code owner

@alexdowad alexdowad Awaiting requested review from alexdowad alexdowad will be requested when the pull request is marked ready for review alexdowad is a code owner

@youkidearitai youkidearitai Awaiting requested review from youkidearitai youkidearitai will be requested when the pull request is marked ready for review youkidearitai is a code owner

@derickr derickr Awaiting requested review from derickr derickr will be requested when the pull request is marked ready for review derickr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /