Skip to content

Fix leak on double DatePeriod::__construct() call#22643

Open
iluuu1994 wants to merge 1 commit into
php:PHP-8.4from
iluuu1994:dateperiod-double-constructor-leak
Open

Fix leak on double DatePeriod::__construct() call#22643
iluuu1994 wants to merge 1 commit into
php:PHP-8.4from
iluuu1994:dateperiod-double-constructor-leak

Conversation

@iluuu1994

@iluuu1994 iluuu1994 commented Jul 8, 2026

Copy link
Copy Markdown
Member

See https://github.com/php/php-src/actions/runs/28911263674/job/85769105449.

Normally we might want to discuss whether such code is even sensible, but it seems carbon is relying on it, as evidenced by the CI failure above. A minimal carbon example that reproduces the error:

<?php

use Carbon\Carbon;

require __DIR__ . '/vendor/autoload.php';

$day = Carbon::now();
$period = Carbon::now()->toPeriod($day);

Just remembered, will have to rebase onto 8.2 to keep nightly green.

@iluuu1994 iluuu1994 requested a review from derickr as a code owner July 8, 2026 17:21
@iluuu1994 iluuu1994 requested a review from TimWolla July 8, 2026 17:21

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just looked at the diff, didn't check for completeness. I trust you there.

Comment thread ext/date/php_date.c
if (period_obj->interval) {
timelib_rel_time_dtor(period_obj->interval);
}
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
memset(period_obj, 0, offsetof(php_period_obj, std));

We only removed XtOffsetOf with 8.6, but offsetof() is reliably available even for 8.4.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I remembered your change. Will have to be backported to 8.2, so I'd prefer just changing on master to match your other PR.

@iluuu1994

Copy link
Copy Markdown
Member Author

@kylekatarnls I hope it's ok to ping you directly. Just wanted to check with you whether the double constructor call is even intentional. This issue popped up recently in our CI, so I figured it might not be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants