Skip to content

[#45] Fix palloc leak and NUL-termination in list_files() - #46

Open
hardikkaurani wants to merge 1 commit into
pgmoneta:mainfrom
hardikkaurani:fix/list-files-memory-leak
Open

hardikkaurani wants to merge 1 commit into
pgmoneta:mainfrom
hardikkaurani:fix/list-files-memory-leak

Conversation

@hardikkaurani

Copy link
Copy Markdown

Fixes #45

Summary

  • Skips . and .. in list_files() (src/pgmoneta_ext/lib.c) before snprintf(), stat(), or palloc().
  • Allocates struct path_info via palloc() only after confirming stat() succeeds and the entry is a directory or regular file, avoiding leaked allocations in multi_call_memory_ctx on . / .., stat() failures, and special files.
  • Replaces strncpy(p_info->name, path, MAX_PATH) with snprintf(p_info->name, MAX_PATH, %s, path) to guarantee NUL-termination.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Author

@jesperpedersen Ready for review! This fixes #45 by skipping . and .. early in list_files() (src/pgmoneta_ext/lib.c), deferring palloc(sizeof(struct path_info)) until after stat() and file-type validation, and using snprintf() to guarantee NUL-termination of p_info->name.

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.

Memory leak in list_files(): p_info is allocated before checking for . and .. or stat errors

2 participants