podman-container-tools/podman · error

malloc: %m

Error message

malloc: %m

What it means

Before the Go runtime starts, podman's C preamble runs preexec hooks: exec_binary() forks and the child mallocs an argv vector of (argc + 2) char* pointers to execv() the hook (pkg/rootless/rootless_linux.c:381). This message means that malloc failed (ENOMEM) and the child exits with EXIT_FAILURE, which the parent propagates as the podman exit status. It is an out-of-memory condition in the forked hook child.

Source

Thrown at pkg/rootless/rootless_linux.c:384

static void
exec_binary (const char *path, char **argv, int argc)
{
  int r, status = 0;
  pid_t pid;

  pid = fork ();
  if (pid < 0)
    {
      fprintf (stderr, "fork: %m\n");
      exit (EXIT_FAILURE);
    }
  if (pid == 0)
    {
      size_t i;
      char **newargv = malloc ((argc + 2) * sizeof(char *));
      if (!newargv)
        {
          fprintf (stderr, "malloc: %m\n");
          exit (EXIT_FAILURE);
        }
      newargv[0] = (char*) path;
      for (i = 0; i < argc; i++)
        newargv[i+1] = argv[i];

      newargv[i+1] = NULL;
      errno = 0;
      execv (path, newargv);
      /* If the file was deleted in the meanwhile, return success.  */
      if (errno == ENOENT)
        exit (EXIT_SUCCESS);
      exit (EXIT_FAILURE);
    }

  r = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
  if (r < 0)
    {

View on GitHub (pinned to a2409076ef)

Solutions

  1. Check and raise memory limits: run 'ulimit -v' and set it to unlimited (or the hard limit); inspect 'systemctl show user-$(id -u) -p MemoryMax' and the cgroup memory.max for the session
  2. Check for OOM kills and free memory: 'dmesg | grep -i oom' / 'journalctl -k', then re-run the command
  3. Confirm the hooks path is involved by temporarily removing /etc/containers/podman_preexec_hooks.txt (or the failing hook) and re-running
  4. If it reproduces with sane limits, collect 'strace -f -e trace=malloc%' or a memory-limit report and open an upstream issue

Example fix

# before
$ ulimit -v 65536
$ podman run alpine ls
malloc: Cannot allocate memory

# after
$ ulimit -v unlimited
$ podman run alpine ls
Defensive patterns

Strategy: validation

Validate before calling

# Pre-flight before running podman with preexec hooks enabled
if [ -e /etc/containers/podman_preexec_hooks.txt ]; then
  # hooks will run; make sure address-space limits are not restrictive
  soft=$(ulimit -Sv); hard=$(ulimit -Hv)
  [ "$hard" = unlimited ] || [ "$soft" -lt "$hard" ] && ulimit -v "$hard" 2>/dev/null
fi
podman "$@"

Try / catch

if ! podman "$@"; then
  rc=$?
  # 'malloc:' from the C helper is fatal; inspect limits before retrying once
  ulimit -v; free -m
  exit "$rc"
fi

Prevention

When it happens

Trigger: Any podman invocation while the indicator file /etc/containers/podman_preexec_hooks.txt exists and one of the hook dirs (LIBEXECPODMAN/pre-exec-hooks, /etc/containers/pre-exec-hooks, or $PODMAN_PREEXEC_HOOKS_DIR) contains at least one entry, combined with memory exhaustion: RLIMIT_AS / 'ulimit -v' cap reached, cgroup MemoryMax hit, or host OOM pressure.

Common situations: Restrictive 'ulimit -v' inherited from a shell profile or systemd unit; a low MemoryMax on the user slice running rootless podman; very long podman command lines (large argc inflates the allocation); heavily loaded CI runners.

Related errors


AI-assisted analysis of podman-container-tools/podman@a2409076ef (2026-08-15). Data as JSON: /api/errors/b8bd0ae2faa129a2. Report an issue: GitHub.