Cocoa port work

This patch makes the Cocoa UI build again, fixes a potential memory leak, and ups the minimum OS X version to 10.5.