Fix potential segfault, add support for MacOS X locks