Fixed possible memory leak (free(opt) was inside if and moved kalloc before lockings.