Memory leak when a property returns a value

RESOLVED INVALID

Status

()

Core
Plug-ins
--
major
RESOLVED INVALID
14 years ago
14 years ago

People

(Reporter: Vlad Alexander, Assigned: jst)

Tracking

({mlk})

Trunk
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1
Build Identifier: Build: 2004083008

There appears to be a memory leak when a property returns a value. If the
property is a string, the plug-in alloc some memory for that string and returns
it to script engine. It appears that the script engine does not release it. The
same thing happens to the Invoke function. We were able to identify this by
debugging our plug-in. Every time the browser is closed, the VC++ debug
environment reports that there is a memory leak. For example, the GetProperty
function malloc memory to the return value but it appears that it never gets
released.

bool
ScriptablePluginObjectBase::GetProperty(NPIdentifier name, NPVariant
*result)
{
  if (name == sBar_id) {
    STRINGZ_TO_NPVARIANT(strdup("Hi, I'm bar"), *result);
    return true;
  }
  VOID_TO_NPVARIANT(*result);
  return false;
}

Reproducible: Always
Steps to Reproduce:
Keywords: mlk
NPObjWrapper_GetProperty may fail after calling thru npobj->_class->getProperty
but before:

    *vp = NPVariantToJSVal(npp, cx, &npv);
                                                                                
    // *vp now owns the value, release our reference.
    _releasevariantvalue(&npv);

if LookupNPP returns null.  Could that be happening here?  Confirming for now so
jst can render a verdict.

/be
Assignee: nobody → jst
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 2

14 years ago
Cause of memory leak: the memory alloc from our plugin is in different program
stack, so that it cannnot be release from mozilla browser.

Solution: Use NPN_MemAlloc function to alloc memory at mozilla browser's memory
stack.
Status: NEW → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.