mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 5679. Fix leak from XPConnect glue.
This commit is contained in:
parent
32d77304e1
commit
0e6d8ebdba
@ -152,22 +152,27 @@ nsJSUtils::nsConvertXPCObjectToJSVal(nsISupports* aSupports,
|
||||
JSContext* aContext,
|
||||
jsval* aReturn)
|
||||
{
|
||||
nsresult rv;
|
||||
*aReturn = JSVAL_NULL; // a sane value, just in case something blows up
|
||||
if (aSupports != nsnull) {
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv);
|
||||
if (NS_FAILED(rv)) return;
|
||||
|
||||
*aReturn = nsnull; // a sane value, just in case something blows up
|
||||
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsIXPConnectWrappedNative* wrapper;
|
||||
nsresult rv = xpc->WrapNative(aContext, aSupports, aIID, &wrapper);
|
||||
rv = xpc->WrapNative(aContext, aSupports, aIID, &wrapper);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
JSObject* obj;
|
||||
rv = wrapper->GetJSObject(&obj);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// set the return value
|
||||
*aReturn = OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
NS_RELEASE(wrapper);
|
||||
}
|
||||
// Yes, this is bizarre, but since this method used in a very
|
||||
// specific ways in idlc-generated code, it's okay. And yes, it's
|
||||
// really the semantics that we want.
|
||||
NS_RELEASE(aSupports);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
|
@ -66,7 +66,7 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
@ -110,7 +110,7 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
|
||||
a->SetDatabase(prop);
|
||||
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -573,7 +573,7 @@ static const char *kObjectGetCaseStr =
|
||||
" nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);\n";
|
||||
|
||||
static const char *kXPIDLObjectGetCaseStr =
|
||||
" // get the js object\n"
|
||||
" // get the js object; n.b., this will do a release on 'prop'\n"
|
||||
" nsJSUtils::nsConvertXPCObjectToJSVal(prop, %s::GetIID(), cx, vp);\n";
|
||||
|
||||
static const char *kStringGetCaseStr =
|
||||
@ -706,6 +706,8 @@ static const char *kXPIDLObjectSetCaseStr =
|
||||
|
||||
static const char *kObjectSetCaseEndStr = "NS_IF_RELEASE(prop);";
|
||||
|
||||
static const char* kXPIDLObjectSetCaseEndStr = kObjectSetCaseEndStr;
|
||||
|
||||
static const char *kStringSetCaseStr =
|
||||
" nsJSUtils::nsConvertJSValToString(prop, cx, *vp);\n";
|
||||
|
||||
@ -773,7 +775,11 @@ JSStubGen::GeneratePropSetter(ofstream *file,
|
||||
break;
|
||||
}
|
||||
|
||||
end_str = aAttribute.GetType() == TYPE_OBJECT ? kObjectSetCaseEndStr : "";
|
||||
switch (aAttribute.GetType()) {
|
||||
case TYPE_OBJECT: end_str = kObjectSetCaseEndStr; break;
|
||||
case TYPE_XPIDL_OBJECT: end_str = kXPIDLObjectSetCaseEndStr; break;
|
||||
default: end_str = ""; break;
|
||||
}
|
||||
if (aIsPrimary) {
|
||||
sprintf(buf, kSetCaseStr, attr_type, case_buf, attr_name, end_str);
|
||||
}
|
||||
@ -1007,6 +1013,7 @@ static const char *kMethodObjectRetStr =
|
||||
" nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);\n";
|
||||
|
||||
static const char *kMethodXPIDLObjectRetStr =
|
||||
" // n.b., this will release nativeRet\n"
|
||||
" nsJSUtils::nsConvertXPCObjectToJSVal(nativeRet, %s::GetIID(), cx, rval);\n";
|
||||
|
||||
static const char *kMethodStringRetStr =
|
||||
|
@ -72,7 +72,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
|
@ -66,7 +66,7 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
// get the js object; n.b., this will do a release on 'prop'
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
}
|
||||
else {
|
||||
@ -110,7 +110,7 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
|
||||
a->SetDatabase(prop);
|
||||
|
||||
NS_IF_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user