[webkit-help] WebKit2 Callback structs are leaked

Adam Roben aroben at apple.com
Thu Jan 27 10:28:51 PST 2011

On 1/27/2011 10:25 AM, Nick Guenther wrote:
> Hello all,
> I am experimenting with Webkit, trying to get it to do offscreen rendering. I have a small WinAPI C app that uses WebKit2. I notice that while there are Set*Client() methods, there don't seem to be any way to get your clients back out. So I have code like:
> 	WKPageLoaderClient *loader_callbacks = (WKPageLoaderClient*)malloc(sizeof(WKPageLoaderClient)); //FIXME: this leaks
> 	memset(loader_callbacks, 0, sizeof(WKPageLoaderClient));
> 	loader_callbacks->didFinishLoadForFrame = onLoad;
> Which of course is in some function and ends up leaking loader_callbacks since that pointer is only kept around locally. The solution right now is to keep all my pointers around somewhere, or make the structs themselves global. But Globals Are Bad (TM), so for my future-curiosity I'm wondering if there plans to make Get*Client() methods or make WebKit2 free all the handlers? How is this supposed to be used?
> Thanks in advance. Any insight would really clear things up for me.

The client struct is copied when you pass it to 
WKPageSetPageLoaderClient, so you can allocate it on the stack and just 
pass its address (or allocate it on the heap and free it after 
WKPageSetPageLoaderClient returns).


More information about the webkit-help mailing list