From 96e1e139cd2f5e2fc4218acba51798fd01abbf90 Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Wed, 12 May 1999 02:50:12 +0000 Subject: [PATCH] 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. --- network/cnvts/cvplugin.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/network/cnvts/cvplugin.cpp b/network/cnvts/cvplugin.cpp index 29c11f77b65..e80b05063c8 100644 --- a/network/cnvts/cvplugin.cpp +++ b/network/cnvts/cvplugin.cpp @@ -25,6 +25,7 @@ #include "nsINetPluginInstance.h" #include "nsIComponentManager.h" #include "nsNetConverterStream.h" +#include "nsCOMPtr.h" 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; 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; 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; NET_StreamClass *new_stream = NULL; NET_StreamClass *next_stream = NULL; - nsINetPluginInstance *plugin_inst; + nsCOMPtr plugin_inst; nsINetOStream *instance_stream; nsINetOStream *out_stream; nsNetConverterStream *converter_stream; nsCID classID = {0}; + nsresult rv = NS_OK; if (URL_s->transfer_encoding != NULL) { @@ -196,9 +204,9 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w) 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; break; @@ -221,8 +229,8 @@ NET_PluginStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w) } converter_stream->Initialize((void *)next_stream); - - if (NS_OK != converter_stream->QueryInterface(kINetOStreamIID, (void **)&out_stream)) + rv = converter_stream->QueryInterface(kINetOStreamIID, (void **)&out_stream); + if (NS_FAILED(rv)) { delete converter_stream; 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); - - if (NS_OK != plugin_inst->QueryInterface(kINetOStreamIID, (void **)&instance_stream)) + rv = plugin_inst->QueryInterface(kINetOStreamIID, (void **)&instance_stream); + if (NS_FAILED(rv)) { delete converter_stream; error = PR_TRUE;