w_parse_string: Correctly handle premature end of strings

Providing invalid input with unterminated strings would cause a segfault. This
patch properly makes w_parse_string() return NULL when an unterminated string
is found, and avoids leaking the memory being held by the string buffer.