Allocate cmd string with alloca instead of malloc, close popen handle if fgets fails.