Fix undefined behavior when destroying a search context.

Also, fix a compile error with memchr for GCC 4.4.7