Fix corner cases in http parsing

This patch adds checks for malloc / strdup, and free all memory when such call fails.