Fixed: crash + leak

Fixed: Race condition due to bad lock syntax
Fixed: all leaks with the my use of the lib