podman-container-tools/podman · error
realloc buffer: %m
Error message
realloc buffer: %m
What it means
While listing a preexec-hooks directory, do_preexec_hooks_dir() grows a buffer one NAME_MAX+1 (256-byte) slot per directory entry with realloc() (pkg/rootless/rootless_linux.c:438). This message means that realloc returned NULL (ENOMEM) and podman exits before the Go runtime starts. The buffer scales linearly with the number of entries in the hooks dir.
Solutions
- Count entries in the reported dir ('ls <dir> | wc -l') and remove non-hook files - only regular executables are used
- Point PODMAN_PREEXEC_HOOKS_DIR at a small dedicated directory containing only the hooks
- Raise memory limits ('ulimit -v unlimited') or relieve memory pressure and re-run
- Remove /etc/containers/podman_preexec_hooks.txt if the hooks are not needed
Example fix
# before export PODMAN_PREEXEC_HOOKS_DIR=/usr/bin # thousands of entries podman ps # realloc buffer: Cannot allocate memory # after mkdir -p ~/hooks && cp /path/to/my-hook ~/hooks/ export PODMAN_PREEXEC_HOOKS_DIR=~/hooks podman ps
Defensive patterns
Strategy: validation
Validate before calling
# Keep the hooks dir small enough that the realloc buffer is trivial
count=$(ls -1 "${PODMAN_PREEXEC_HOOKS_DIR:-/etc/containers/pre-exec-hooks}" 2>/dev/null | wc -l)
if [ "$count" -gt 1000 ]; then
echo "too many entries ($count) in preexec hooks dir" >&2
exit 1
fi
Prevention
- Never point PODMAN_PREEXEC_HOOKS_DIR at system bin directories
- Curate hooks to the minimum set actually needed
- Keep memory limits generous when hooks are enabled
When it happens
Trigger: A preexec-hooks directory containing a very large number of files combined with memory pressure or an RLIMIT_AS/cgroup cap; allocation size is (nfiles+1)*256 bytes.
Common situations: Someone points PODMAN_PREEXEC_HOOKS_DIR at a directory with tens of thousands of files (e.g. a bin dir or a temp dir) instead of a curated hooks dir; low 'ulimit -v'; host near OOM.
Related errors
- malloc: %m
- unable to print to string
- save socket listen environments error: %m
- waitpid: %m
- cannot block signals: %m\n
AI-assisted analysis of podman-container-tools/podman@a2409076ef (2026-08-15).
Data as JSON: /api/errors/eb18ebcebc7eab04.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/rootless/rootless_linux.c:441
d = opendir (dir);
if (!d)
{
if (errno != ENOENT)
{
fprintf (stderr, "opendir %s: %m\n", dir);
exit (EXIT_FAILURE);
}
return;
}
errno = 0;
for (de = readdir (d); de; de = readdir (d))
{
buffer = realloc (buffer, (nfiles + 1) * (NAME_MAX + 1));
if (buffer == NULL)
{
fprintf (stderr, "realloc buffer: %m\n");
exit (EXIT_FAILURE);
}
if (de->d_type != DT_REG)
continue;
strncpy (buffer + nfiles * (NAME_MAX + 1), de->d_name, NAME_MAX + 1);
nfiles++;
}
qsort (buffer, nfiles, NAME_MAX + 1, (int (*)(const void *, const void *)) strcmp);
for (i = 0; i < nfiles; i++)
{
const char *fname = buffer + i * (NAME_MAX + 1);
char path[PATH_MAX];
struct stat st;
int ret;View on GitHub (pinned to a2409076ef)