memory leaks when ocx return string

145 views
Skip to first unread message

huzhongshan

unread,
Jun 7, 2012, 8:50:18 AM6/7/12
to ff-activex-host
I found there is a memory leaks when ocx method return string . I test
it in Chrome with ff-activex-host r39.

the ocx method , it just return a string :

BSTR CMemTestCtrl::GetString(LPCTSTR inputString)
{
CString strResult;
// TODO: Add your dispatch handler code here
for (int i=0; i<100000; i++)
{
strResult += inputString;
}

return strResult.AllocSysString();
}


sample html to call above method :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chrome plugin memory leak sample </title>
<script type="text/javascript">

function Test(){
//- loop 100 thound times to add string ,return value about 1M
MemCtrl.GetString("a123456789");

alert('over');
}
</script>
</head>
<body>
<object id="MemCtrl" width="100" height="100" TYPE="application/x-itst-
activex" clsid="{E8B974C1-B7D4-4986-B419-F5A3A93CC6CE}"></object>
<input type="button" value="Test" onclick="Test();">
</body>
</html>

Amaya Biano

unread,
Jun 24, 2012, 2:39:00 PM6/24/12
to ff-acti...@googlegroups.com

Leeor Aharon

unread,
Jun 26, 2012, 11:19:47 AM6/26/12
to ff-acti...@googlegroups.com
Sorry it took me a long time to reply.

The string returned by the method is converted to an NPvar object, and the problem is that memory is allocated as a part of that conversion. For some reason, that memory is not cleaned up when the object wrapping the string gets its refcount reduced when the Javascript garbage collects it (assuming that it does).

If you want to look deeper into the issue (I don't have the capacity to look into it myself right now), the code you should be looking at is in scriptable.h (invoking the method and returning the string) and variants.cpp (converting COM variants to NPvars). If you send me a patch, I'll merge it to the project.

Leeor.

--
You received this message because you are subscribed to the Google Groups "ff-activex-host" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ff-activex-host/-/HznL0JbVVxIJ.

To post to this group, send email to ff-acti...@googlegroups.com.
To unsubscribe from this group, send email to ff-activex-ho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ff-activex-host?hl=en.

huzhongshan

unread,
Jun 30, 2012, 6:31:18 AM6/30/12
to ff-acti...@googlegroups.com
I found that  https://code.google.com/p/np-activex/   which derived from ffactivex solved the problem , I compared the source code , but cannot find where the bugs are in ffactivex.

To post to this group, send email to ff-activex-host@googlegroups.com.
To unsubscribe from this group, send email to ff-activex-host+unsubscribe@googlegroups.com.

David Xue

unread,
Apr 4, 2013, 8:42:35 PM4/4/13
to ff-acti...@googlegroups.com
I sync'd down np-activex and it seems to use almost the exact same scriptable.h and variants.cpp (aside from some implementation moved from scriptable.h to scriptable.cpp and some refactoring in Invoke()). The code for Variant2NPVar() and BSTR2NPVar() is the same.

Leeor when you are talking about the memory not being cleaned up, are you referring to the char *npStr that is allocated from NPFuncs.memalloc()? Do we need to call NPN_MemFree() when we are done?

To post to this group, send email to ff-acti...@googlegroups.com.
To unsubscribe from this group, send email to ff-activex-ho...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages