If you're going to handle malloc failures then you need to clean up previously allocated memory (like `pkt_out` and `list`).