зеркало из https://github.com/mozilla/pjs.git
Cleanup some of the memory leaks in this code. We were never releasing the stream converter that was attached to the stream! The stream struct was just getting PR_Free'd. So I tweaked plugin_stream_complete and plugin_stream_abort to release the converter. And we had another leak on the pluggable converter object which was in NET_PluginStream. Using nsCOMPtr to fix the leak. Also fixed where we were comparing a nsresult directly against NS_OK instead of using NS_SUCCEEDED.
This commit is contained in:
Родитель
217cdcbd7f
Коммит
96e1e139cd
|
@ -25,6 +25,7 @@
|
||||||
#include "nsINetPluginInstance.h"
|
#include "nsINetPluginInstance.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsNetConverterStream.h"
|
#include "nsNetConverterStream.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
|
||||||
static NS_DEFINE_CID(kINetPluginCID, NS_INET_PLUGIN_CID);
|
static NS_DEFINE_CID(kINetPluginCID, NS_INET_PLUGIN_CID);
|
||||||
|
@ -39,6 +40,9 @@ plugin_stream_complete(NET_StreamClass *stream)
|
||||||
nsINetOStream *instance_stream = (nsINetOStream *)stream->data_object;
|
nsINetOStream *instance_stream = (nsINetOStream *)stream->data_object;
|
||||||
|
|
||||||
instance_stream->Complete();
|
instance_stream->Complete();
|
||||||
|
// mscott -- release instance_stream because we are done with it..
|
||||||
|
// the owner of the NET_Stream object just frees the struct..
|
||||||
|
NS_RELEASE(instance_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +52,9 @@ plugin_stream_abort(NET_StreamClass *stream, int status)
|
||||||
nsINetOStream *instance_stream = (nsINetOStream *)stream->data_object;
|
nsINetOStream *instance_stream = (nsINetOStream *)stream->data_object;
|
||||||
|
|
||||||
instance_stream->Abort(status);
|
instance_stream->Abort(status);
|
||||||
|
// mscott -- release instance_stream because we are done with it..
|
||||||
|
// the owner of the NET_Stream object just frees the struct..
|
||||||
|
NS_RELEASE(instance_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,11 +168,12 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w)
|
||||||
const char *mime_type_out;
|
const char *mime_type_out;
|
||||||
NET_StreamClass *new_stream = NULL;
|
NET_StreamClass *new_stream = NULL;
|
||||||
NET_StreamClass *next_stream = NULL;
|
NET_StreamClass *next_stream = NULL;
|
||||||
nsINetPluginInstance *plugin_inst;
|
nsCOMPtr <nsINetPluginInstance> plugin_inst;
|
||||||
nsINetOStream *instance_stream;
|
nsINetOStream *instance_stream;
|
||||||
nsINetOStream *out_stream;
|
nsINetOStream *out_stream;
|
||||||
nsNetConverterStream *converter_stream;
|
nsNetConverterStream *converter_stream;
|
||||||
nsCID classID = {0};
|
nsCID classID = {0};
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
if (URL_s->transfer_encoding != NULL)
|
if (URL_s->transfer_encoding != NULL)
|
||||||
{
|
{
|
||||||
|
@ -196,9 +204,9 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsComponentManager::CreateInstance(classID, (nsISupports *)nsnull, kINetPluginInstanceIID, (void **)&plugin_inst);
|
nsComponentManager::CreateInstance(classID, (nsISupports *)nsnull, kINetPluginInstanceIID, (void **) getter_AddRefs(plugin_inst));
|
||||||
|
|
||||||
if (plugin_inst == NULL)
|
if (!plugin_inst)
|
||||||
{
|
{
|
||||||
error = PR_TRUE;
|
error = PR_TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -221,8 +229,8 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w)
|
||||||
}
|
}
|
||||||
|
|
||||||
converter_stream->Initialize((void *)next_stream);
|
converter_stream->Initialize((void *)next_stream);
|
||||||
|
rv = converter_stream->QueryInterface(kINetOStreamIID, (void **)&out_stream);
|
||||||
if (NS_OK != converter_stream->QueryInterface(kINetOStreamIID, (void **)&out_stream))
|
if (NS_FAILED(rv))
|
||||||
{
|
{
|
||||||
delete converter_stream;
|
delete converter_stream;
|
||||||
error = PR_TRUE;
|
error = PR_TRUE;
|
||||||
|
@ -230,8 +238,8 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w)
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_inst->Initialize(out_stream, URL_s->address);
|
plugin_inst->Initialize(out_stream, URL_s->address);
|
||||||
|
rv = plugin_inst->QueryInterface(kINetOStreamIID, (void **)&instance_stream);
|
||||||
if (NS_OK != plugin_inst->QueryInterface(kINetOStreamIID, (void **)&instance_stream))
|
if (NS_FAILED(rv))
|
||||||
{
|
{
|
||||||
delete converter_stream;
|
delete converter_stream;
|
||||||
error = PR_TRUE;
|
error = PR_TRUE;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче