Fix possible illegal memory access

Change-Id: If0998373f306adf4f87ed4904e467f65b64f8c1b
Reviewed-on: http://review.couchbase.org/24646
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>