Fix error case leak in nsPluginFile::GetPluginInfo. b=462023 r=mstange sr=jst

This commit is contained in:
Josh Aas 2008-12-09 12:15:49 -05:00
parent 70f9b5f422
commit e3d671ca8a
4 changed files with 18 additions and 31 deletions

View File

@ -4867,13 +4867,11 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir,
#endif
// create a tag describing this plugin.
nsPluginInfo info = { sizeof(info) };
nsPluginInfo info;
memset(&info, 0, sizeof(info));
nsresult res = pluginFile.GetPluginInfo(info);
if (NS_FAILED(res))
continue;
// if we don't have mime type -- don't proceed, this is not a plugin
if (!info.fMimeTypeArray) {
// if we don't have mime type don't proceed, this is not a plugin
if (NS_FAILED(res) || !info.fMimeTypeArray) {
pluginFile.FreePluginInfo(info);
continue;
}

View File

@ -57,7 +57,6 @@ public:
struct PRLibrary;
struct nsPluginInfo {
PRUint32 fPluginInfoSize; // indicates how large the structure is currently.
char* fName; // name of the plugin
char* fDescription; // etc.
PRUint32 fVariantCount;

View File

@ -375,10 +375,7 @@ private:
nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
{
// clear out the info, except for the first field.
memset(&info.fName, 0, sizeof(info) - sizeof(PRUint32));
if (info.fPluginInfoSize < sizeof(nsPluginInfo))
return NS_ERROR_FAILURE;
memset(&info, 0, sizeof(info));
// First open up resource we can use to get plugin info.
@ -492,9 +489,6 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
}
}
//XXX FIXME: past this point some (unlikely) error cases will leak memory
// (leak is bug 462023)
// Fill in the info struct based on the data in the BPSupportedMIMETypes struct
int variantCount = info.fVariantCount;
info.fMimeTypeArray = static_cast<char**>(NS_Alloc(variantCount * sizeof(char*)));
@ -529,22 +523,20 @@ nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info)
nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info)
{
if (info.fPluginInfoSize <= sizeof(nsPluginInfo)) {
NS_Free(info.fName);
NS_Free(info.fDescription);
int variantCount = info.fVariantCount;
for (int i = 0; i < variantCount; i++) {
NS_Free(info.fMimeTypeArray[i]);
NS_Free(info.fExtensionArray[i]);
NS_Free(info.fMimeDescriptionArray[i]);
}
NS_Free(info.fMimeTypeArray);
NS_Free(info.fMimeDescriptionArray);
NS_Free(info.fExtensionArray);
NS_Free(info.fFileName);
NS_Free(info.fFullPath);
NS_Free(info.fVersion);
NS_Free(info.fName);
NS_Free(info.fDescription);
int variantCount = info.fVariantCount;
for (int i = 0; i < variantCount; i++) {
NS_Free(info.fMimeTypeArray[i]);
NS_Free(info.fExtensionArray[i]);
NS_Free(info.fMimeDescriptionArray[i]);
}
NS_Free(info.fMimeTypeArray);
NS_Free(info.fMimeDescriptionArray);
NS_Free(info.fExtensionArray);
NS_Free(info.fFileName);
NS_Free(info.fFullPath);
NS_Free(info.fVersion);
return NS_OK;
}

View File

@ -228,8 +228,6 @@ nsresult nsPluginFile::GetPluginInfo( nsPluginInfo &info)
while( ret == NO_ERROR)
{
info.fPluginInfoSize = sizeof( nsPluginInfo);
info.fName = LoadRCDATAString( hPlug, NS_INFO_ProductName);
info.fVersion = LoadRCDATAVersion( hPlug, NS_INFO_ProductVersion);