add a fix for memleaks caused by failed memory allocations