Fix corner cases in http parsing

This patch adds checks for malloc / strdup, and free all memory
when such call fails.
Merge pull request #1780 from hardening/http_malloc_fixes

Fix corner cases in http parsing