fix some segfaults

This commit has been contributed by someone who despises github's
force-https behaviour and who didn't find upstream email contact
to send a patch; feel free to adapt it as you like, copyright is
assigned to upstream.

Here's a reference to quite tangential posting in Russian regarding
a completely different discussion that resulted in me proposing
to proxy the patches considered worthwile (I know that person online
for some time and he seems knowledgeable albeit rough):

http://www.opennet.ru/openforum/vsluhforumID3/93380.html#172

HTH