Fix a refcounting bug & menu index bug

The recent separator-skipping change exposed a double release
of cocoa_items, and while working on it I noticed a couple of
paths where last_item wasn't updated, which might result in
separators being skipped incorrectly.