{"record":{"id":"b4f53252b6cdd708","repo":"podman-container-tools/podman","slug":"failed-to-allocate-ps-argv","errorCode":null,"errorMessage":"failed to allocate ps argv","messagePattern":"failed to allocate ps argv","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libpod/container_top_linux.c","lineNumber":26,"sourceCode":"#include <stdio.h>\n#include <stdlib.h>\n#include <sys/mount.h>\n#include <sys/wait.h>\n#include <unistd.h>\n\n/* keep special_exit_code in sync with container_top_linux.go */\nint special_exit_code = 255;\nint join_userns = 0;\nchar **argv = NULL;\n\nvoid\ncreate_argv (int len)\n{\n  /* allocate one extra element because we need a final NULL in c */\n  argv = malloc (sizeof (char *) * (len + 1));\n  if (argv == NULL)\n    {\n      fprintf (stderr, \"failed to allocate ps argv\");\n      exit (special_exit_code);\n    }\n  /* add final NULL */\n  argv[len] = NULL;\n}\n\nvoid\nset_argv (int pos, char *arg)\n{\n  argv[pos] = arg;\n}\n\nvoid\nset_userns ()\n{\n  join_userns = 1;\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/podman-container-tools/podman/blob/a2409076ef2fef60ad9ac046375dedc7d9410ef4/libpod/container_top_linux.c#L8-L44","documentation":"C helper behind 'podman top': create_argv() (called from podmanTopInner in libpod/container_top_linux.go:133) mallocs (len+1) char* slots for the argv of the ps command and exits 255 (special_exit_code, kept in sync with the Go side) when malloc returns NULL. len is the number of ps arguments: the ps binary path plus every ps option/descriptor passed to 'podman top'. A NULL return means the reexec'ed podman process could not allocate memory — real OOM, a tiny RLIMIT_AS, or an absurd argument count.","triggerScenarios":"'podman top CTOR [ps options...]' on a host where the reexec'ed helper is under a cgroup memory limit or ulimit -v that the small malloc exceeds; passing an enormous number/column list of ps descriptors; fork/exec under severe memory pressure. The error appears on stderr of 'podman top' and the command exits 255.","commonSituations":"cgroups v2 memory.max set very low (systemd slices like MemoryMax=10M); heavy swap exhaustion; scripts looping 'podman top' with long -o column lists; ulimit -v inherited from a restricted service unit.","solutions":["Retry 'podman top' without extra ps options (fewer arguments, smaller allocation)","Raise the memory limit on the podman process's cgroup (systemd MemoryMax/arena) or ulimit -v","Free memory / check for OOM killer activity (dmesg | tail) and retry when pressure passes","If persistent, report upstream with 'podman info' — allocation size is only pointer-sized per ps arg, so failure indicates environment-level memory starvation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Sanity-check process limits and arg count before sampling with podman top\n#!/bin/sh\n# 1. keep ps descriptor lists modest (each becomes an argv slot)\n[ $# -le 32 ] || { echo 'too many top descriptors' >&2; exit 1; }\n# 2. make sure the calling context is not memory-starved\nulimit -v 2>/dev/null | grep -qv unlimited || true\nv=$(ulimit -v 2>/dev/null || echo unlimited)\n[ \"$v\" = unlimited ] || [ \"$v\" -gt 65536 ] || { echo \"ulimit -v too low: $v\" >&2; exit 1; }\nexec podman top \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass few ps options to 'podman top' (or none) — argv size scales with descriptors","Watch cgroup memory limits (MemoryMax, memory.max) on the slice running podman; a tiny malloc failing signals starvation","If 'podman top' exits 255 with this on stderr, check dmesg for OOM kills before assuming a podman bug"],"tags":["podman-top","cgo","memory","malloc"],"backgroundTag":null,"analyzedSha":"a2409076ef2fef60ad9ac046375dedc7d9410ef4","analyzedAt":"2026-08-15T15:57:05.625Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}