SF # 669553, fix memory (ref) leaks

Will backport.
2 files changed