added null terminator after malloc in cmd.c