{"record":{"id":"eb18ebcebc7eab04","repo":"podman-container-tools/podman","slug":"realloc-buffer-m","errorCode":null,"errorMessage":"realloc buffer: %m\n","messagePattern":"realloc buffer: %m\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rootless/rootless_linux.c","lineNumber":441,"sourceCode":"  d = opendir (dir);\n  if (!d)\n    {\n      if (errno != ENOENT)\n        {\n          fprintf (stderr, \"opendir %s: %m\\n\", dir);\n          exit (EXIT_FAILURE);\n        }\n      return;\n    }\n\n  errno = 0;\n\n  for (de = readdir (d); de; de = readdir (d))\n    {\n      buffer = realloc (buffer, (nfiles + 1) * (NAME_MAX + 1));\n      if (buffer == NULL)\n        {\n          fprintf (stderr, \"realloc buffer: %m\\n\");\n          exit (EXIT_FAILURE);\n        }\n\n      if (de->d_type != DT_REG)\n        continue;\n\n      strncpy (buffer + nfiles * (NAME_MAX + 1), de->d_name, NAME_MAX + 1);\n      nfiles++;\n    }\n\n  qsort (buffer, nfiles, NAME_MAX + 1, (int (*)(const void *, const void *)) strcmp);\n\n  for (i = 0; i < nfiles; i++)\n    {\n      const char *fname = buffer + i * (NAME_MAX + 1);\n      char path[PATH_MAX];\n      struct stat st;\n      int ret;","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/podman-container-tools/podman/blob/a2409076ef2fef60ad9ac046375dedc7d9410ef4/pkg/rootless/rootless_linux.c#L423-L459","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nexport PODMAN_PREEXEC_HOOKS_DIR=/usr/bin   # thousands of entries\npodman ps   # realloc buffer: Cannot allocate memory\n\n# after\nmkdir -p ~/hooks && cp /path/to/my-hook ~/hooks/\nexport PODMAN_PREEXEC_HOOKS_DIR=~/hooks\npodman ps\n","handlingStrategy":"validation","validationCode":"# Keep the hooks dir small enough that the realloc buffer is trivial\ncount=$(ls -1 \"${PODMAN_PREEXEC_HOOKS_DIR:-/etc/containers/pre-exec-hooks}\" 2>/dev/null | wc -l)\nif [ \"$count\" -gt 1000 ]; then\n  echo \"too many entries ($count) in preexec hooks dir\" >&2\n  exit 1\nfi\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["memory","preexec-hooks","c","oom"],"backgroundTag":null,"analyzedSha":"a2409076ef2fef60ad9ac046375dedc7d9410ef4","analyzedAt":"2026-08-15T15:57:05.625Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}