I'm intermixing Symbian C++ and Open C code and have some concerns regarding using cleanup stack with Open C types. What is the official statement on using Open C types and cleanup stack? Is it allowed to put Open C types to the cleanup stack (using TCleanupItem)? Or does Open C has some sort of built-in way to prevent memory leaks with its built-in types? It's noted in the SDK that "Open C APIs assume that a cleanup stack is created and there is a top-level TRAP for the current thread".
For instance, lets see this code example which uses both Open C and Symbian C++ calls:
What happens if the called Symbian method leaves? We created a GString on the heap and didn't push it onto the cleanup stack. Do we get a memory leak or Open C did something in the background which ensured that it cannot happen?Code:GString* string = g_string_new("something"); DoSomeThingThatCanLeaveL(); // Symbian C++ method call, can leave g_string_free(string, TRUE);
Can I put the GString to the cleanup stack (by means of a TCleanupItem)?