snort plugin: Improve error handling.

This prevents file descriptors and memory from leaking if something goes
wrong, e.g. the last line in the file is a comment.