Unfortunately, something is link checking the bundle identifier “org.blenderfoundation.blender” and sending some modifier changed events. This can easily be reproduced with a sample app that implemented - (void)flagsChanged:(NSEvent *)event and sets the bundle identifier to org.blenderfoundation.blender. I can’t isolate what is doing the bundle check (it is outside of blender) and have to change the identifier to get it to work correctly with Wacom Intuous Pro.
Fix leaks on macOS; new allocates a new object that needs to be autoreleased.
NSWindow initWithContentRect.. never returns nil, so it is pointless to check the result.
NSWindow.h starts wtih NS_ASSUME_NONNULL_BEGIN; properties and methods that return nil are explicitly marked nullable.