fix: Fix segmentation fault caused by double-free of field_name - #13
Open
matapatos wants to merge 1 commit into
Open
fix: Fix segmentation fault caused by double-free of field_name#13matapatos wants to merge 1 commit into
matapatos wants to merge 1 commit into
Conversation
The issue was introduced in commit 7325936 which moved the zend_string_release call earlier in the code but didn't remove the release at the end of the loop. This caused a double-free when: - field_value != NULL (field exists or has default) - is_to_release_field_name is true (field_name was allocated) - valid_value != NULL (validation succeeded) In this case, field_name would be released both at the early release point and at the end of the loop, causing a segmentation fault. The fix: 1. Remove the early release that was causing the double-free 2. Add releases at all exception/return paths to prevent memory leaks 3. Move is_to_release_field_name calculation before exception checks 4. Initialize field_name to NULL to avoid potential undefined behavior This ensures field_name is released exactly once in all code paths. Co-authored-by: matapatos <matapatos@users.noreply.github.com>
matapatos
marked this pull request as ready for review
August 4, 2026 05:41
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.
Summary
Root Cause
When processing model properties in the validate function:
The field_name would be released twice:
This double-free causes undefined behavior and segmentation faults.
Solution
Verification
All code paths now release field_name exactly once: