Closed Bug 257539 Opened 20 years ago Closed 20 years ago

Memory leak when a property returns a value

Categories

(Core Graveyard :: Plug-ins, defect)

x86
Windows XP
defect
Not set
major

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: vlad.alexander, Assigned: jst)

Details

(Keywords: memory-leak)

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
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
Closed: 20 years ago
Resolution: --- → INVALID
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.