Skip to content

Fix a leak when gmtlib_read_table deletes an empty segment - #9237

Merged
Esteban82 merged 1 commit into
masterfrom
fix-read-table-empty-segment-leak
Sep 30, 2026
Merged

Esteban82 merged 1 commit into
masterfrom
fix-read-table-empty-segment-leak

Conversation

@Esteban82

Copy link
Copy Markdown
Member

Claude flagged this leak: the row == 0 deletion inside the read loop frees a segment's struct but not its hidden struct, both allocated together in gmt_get_segment. The equivalent deletion after the loop, for a last empty segment (gmt_io.c:8526), already frees both -- this fix does the same here, and also frees the segment's header/label, which it can inherit from the previous file's last segment header when several files are read.

Tested with:

printf '30 45\n120 60\n' | GMT_TRACK_MEMORY=on gmt convert -i0:2

(needs a build with -DMEMDEBUG, GMT's own leak tracker; cmake/ConfigUserAdvanced.cmake has the toggle)

Assisted-by: Claude Opus 5.5; PR text first drafted with Claude Sonnet 5.

🤖 Generated with Claude Code

The row == 0 deletion inside the read loop freed the segment struct but
not its hidden struct, allocated together in gmt_get_segment, nor its
header and label. The deletion after the loop, for a last empty segment,
already frees hidden; that segment never gets a header. The header can
be set here because segment_header still holds the previous file's last
segment header when several files are read.

Tested with (a -DMEMDEBUG build):
  printf '30 45\n120 60\n' | GMT_TRACK_MEMORY=on gmt convert -i0:2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Esteban82
Esteban82 marked this pull request as ready for review September 30, 2026 00:54
@Esteban82
Esteban82 merged commit 9f1a5e9 into master Sep 30, 2026
17 of 20 checks passed
@Esteban82
Esteban82 deleted the fix-read-table-empty-segment-leak branch September 30, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants