fix for #41996 - crash because getter was not pre-allocating the result

fix all callers to ensure they are freeing the result
This commit is contained in:
alecf%netscape.com 2000-06-09 20:58:59 +00:00
Родитель fcd697b0a3
Коммит 0f8f1d7864
6 изменённых файлов: 42 добавлений и 39 удалений

Просмотреть файл

@ -422,7 +422,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
NS_ASSERTION(profileDirSet, "Invalid profileDirSet");
nsresult rv;
char* cmdResult = nsnull;
nsXPIDLCString cmdResult;
nsFileSpec currProfileDirSpec;
#ifdef DEBUG_profile_verbose
@ -435,7 +435,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
// apprunner -P profilename
// runs the app using the profile <profilename>
// remembers profile for next time
rv = cmdLineArgs->GetCmdLineValue(PROFILE_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(PROFILE_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {
@ -490,11 +490,11 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
// runs app using that profile
// remembers profile for next time
rv = cmdLineArgs->GetCmdLineValue(CREATE_PROFILE_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(CREATE_PROFILE_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {
nsAutoString currProfileName; currProfileName.AssignWithConversion(strtok(cmdResult, " "));
nsAutoString currProfileName; currProfileName.AssignWithConversion(strtok(NS_CONST_CAST(char*,(const char*)cmdResult), " "));
nsAutoString currProfileDirString; currProfileDirString.AssignWithConversion(strtok(NULL, " "));
if (!currProfileDirString.IsEmpty()) {
@ -539,7 +539,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
}
// Start Profile Manager
rv = cmdLineArgs->GetCmdLineValue(PROFILE_MANAGER_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(PROFILE_MANAGER_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {
@ -548,7 +548,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
}
// Start Profile Selection
rv = cmdLineArgs->GetCmdLineValue(PROFILE_SELECTION_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(PROFILE_SELECTION_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {
@ -558,7 +558,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
// Start Profile Wizard
rv = cmdLineArgs->GetCmdLineValue(PROFILE_WIZARD_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(PROFILE_WIZARD_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {
@ -567,7 +567,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
}
// Start Migaration activity
rv = cmdLineArgs->GetCmdLineValue(INSTALLER_CMD_LINE_ARG, &cmdResult);
rv = cmdLineArgs->GetCmdLineValue(INSTALLER_CMD_LINE_ARG, getter_Copies(cmdResult));
if (NS_SUCCEEDED(rv))
{
if (cmdResult) {

Просмотреть файл

@ -195,7 +195,7 @@ nsCmdLineService::GetCmdLineValue(const char * aArg, char ** aResult)
for (int i = 0; i<mArgCount; i++)
{
if (ArgsMatch(aArg,(char *) mArgList.ElementAt(i))) {
*aResult = (char *)mArgValueList.ElementAt(i);
*aResult = nsCRT::strdup((char *)mArgValueList.ElementAt(i));
return NS_OK;
}
}

Просмотреть файл

@ -511,19 +511,19 @@ static nsresult HandleArbitraryStartup( nsICmdLineService* cmdLineArgs, nsIPref
nsresult rv;
PRInt32 height = NS_SIZETOCONTENT;
PRInt32 width = NS_SIZETOCONTENT;
char* tempString = NULL;
nsXPIDLCString tempString;
// Get the value of -width option
rv = cmdLineArgs->GetCmdLineValue("-width", &tempString);
rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString));
if (NS_FAILED(rv)) return rv;
if (tempString) PR_sscanf(tempString, "%d", &width);
if ((const char*)tempString) PR_sscanf(tempString, "%d", &width);
// Get the value of -height option
rv = cmdLineArgs->GetCmdLineValue("-height", &tempString);
rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString));
if (NS_FAILED(rv)) return rv;
if (tempString) PR_sscanf(tempString, "%d", &height);
if ((const char*)tempString) PR_sscanf(tempString, "%d", &height);
if (heedGeneralStartupPrefs) {
#ifdef DEBUG_CMD_LINE
@ -679,20 +679,20 @@ static nsresult Ensure1Window( nsICmdLineService* cmdLineArgs)
PRInt32 width = NS_SIZETOCONTENT;
// Get the value of -width option
char* tempString = NULL;
rv = cmdLineArgs->GetCmdLineValue("-width", &tempString);
nsXPIDLCString tempString;
rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString));
if (NS_FAILED(rv))
return rv;
if (tempString)
if ((const char*)tempString)
PR_sscanf(tempString, "%d", &width);
// Get the value of -height option
rv = cmdLineArgs->GetCmdLineValue("-height", &tempString);
rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString));
if (NS_FAILED(rv))
return rv;
if (tempString)
if ((const char*)tempString)
PR_sscanf(tempString, "%d", &height);
rv = OpenBrowserWindow(height, width);

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsString.h"
#include "nsICmdLineService.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIAppShellService.h"
@ -805,26 +806,32 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request ) {
nsCOMPtr<nsICmdLineService> args;
nsresult rv = GetCmdLineArgs( request, getter_AddRefs( args ) );
if ( NS_SUCCEEDED( rv ) ) {
char *arg;
if ( NS_SUCCEEDED( args->GetURLToLoad( &arg ) ) && arg ) {
nsXPIDLCString arg;
if (NS_SUCCEEDED(args->GetURLToLoad(getter_Copies(arg) ) ) &&
(const char*)arg ) {
// Launch browser.
#if MOZ_DEBUG_DDE
printf( "Launching browser on url [%s]...\n", arg );
printf( "Launching browser on url [%s]...\n", (const char*)arg );
#endif
(void)OpenWindow( "chrome://navigator/content/", arg );
} else if ( NS_SUCCEEDED( args->GetCmdLineValue( "-chrome", &arg ) ) && arg ) {
}
else if (NS_SUCCEEDED(args->GetCmdLineValue("-chrome", getter_Copies(arg))) &&
(const char*)arg ) {
// Launch chrome.
#if MOZ_DEBUG_DDE
printf( "Launching chrome url [%s]...\n", arg );
printf( "Launching chrome url [%s]...\n", (const char*)arg );
#endif
(void)OpenWindow( arg, "" );
} else if ( NS_SUCCEEDED( args->GetCmdLineValue( "-edit", &arg ) ) && arg ) {
}
else if (NS_SUCCEEDED(args->GetCmdLineValue("-edit", getter_Copies(arg))) &&
(const char*)arg ) {
// Launch composer.
#if MOZ_DEBUG_DDE
printf( "Launching editor on url [%s]...\n", arg );
#endif
(void)OpenWindow( "chrome://editor/content/", arg );
} else if ( NS_SUCCEEDED( args->GetCmdLineValue( "-mail", &arg ) ) && arg ) {
} else if ( NS_SUCCEEDED( args->GetCmdLineValue( "-mail", getter_Copies(arg))) &&
(const char*)arg ) {
// Launch composer.
#if MOZ_DEBUG_DDE
printf( "Launching mail...\n" );

Просмотреть файл

@ -182,7 +182,7 @@ class PageCycler : public nsIObserver {
public:
NS_DECL_ISUPPORTS
PageCycler(nsBrowserInstance* appCore, char *aTimeoutValue = nsnull)
PageCycler(nsBrowserInstance* appCore, const char *aTimeoutValue = nsnull)
: mAppCore(appCore), mBuffer(nsnull), mCursor(nsnull), mTimeoutValue(0) {
NS_INIT_REFCNT();
NS_ADDREF(mAppCore);
@ -537,23 +537,19 @@ nsBrowserInstance::LoadInitialPage(void)
#ifdef ENABLE_PAGE_CYCLER
// First, check if there's a URL file to load (for testing), and if there
// is, process it instead of anything else.
char* file = 0;
rv = cmdLineArgs->GetCmdLineValue("-f", &file);
if (NS_SUCCEEDED(rv) && file) {
nsXPIDLCString file;
rv = cmdLineArgs->GetCmdLineValue("-f", getter_Copies(file));
if (NS_SUCCEEDED(rv) && (const char*)file) {
// see if we have a timeout value corresponding to the url-file
char *timeoutVal=nsnull;
rv = cmdLineArgs->GetCmdLineValue("-ftimeout", &timeoutVal);
nsXPIDLCString timeoutVal;
rv = cmdLineArgs->GetCmdLineValue("-ftimeout", getter_Copies(timeoutVal));
// cereate the cool PageCycler instance
PageCycler* bb = new PageCycler(this, timeoutVal);
if (bb == nsnull) {
nsCRT::free(file);
nsCRT::free(timeoutVal);
if (bb == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(bb);
rv = bb->Init(file);
nsCRT::free(file);
nsCRT::free(timeoutVal);
if (NS_FAILED(rv)) return rv;
nsAutoString str;

Просмотреть файл

@ -195,7 +195,7 @@ nsCmdLineService::GetCmdLineValue(const char * aArg, char ** aResult)
for (int i = 0; i<mArgCount; i++)
{
if (ArgsMatch(aArg,(char *) mArgList.ElementAt(i))) {
*aResult = (char *)mArgValueList.ElementAt(i);
*aResult = nsCRT::strdup((char *)mArgValueList.ElementAt(i));
return NS_OK;
}
}