(215094) leak city in opera profile migrator. Switch to using XPIDLCStrings to avoid having to manually free cstrings alloced by INI parser

This commit is contained in:
ben%bengoodger.com 2004-02-29 05:56:43 +00:00
Родитель a9034efaa2
Коммит 42793b726a
4 изменённых файлов: 34 добавлений и 41 удалений

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

@ -59,7 +59,7 @@
#include "nsString.h" #include "nsString.h"
// Proxy utilities shared by the Opera and IE migrators // Proxy utilities shared by the Opera and IE migrators
void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch); void ParseOverrideServers(const char* aServers, nsIPrefBranch* aBranch);
void SetProxyPref(const nsACString& aHostPort, const char* aPref, void SetProxyPref(const nsACString& aHostPort, const char* aPref,
const char* aPortPref, nsIPrefBranch* aPrefs); const char* aPortPref, nsIPrefBranch* aPrefs);

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

@ -25,7 +25,7 @@
#include "nsINIParser.h" #include "nsINIParser.h"
nsINIParser::nsINIParser(char *aFilename) nsINIParser::nsINIParser(const char *aFilename)
{ {
FILE *fd = NULL; FILE *fd = NULL;
long eofpos = 0; long eofpos = 0;

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

@ -42,7 +42,7 @@ public:
* *
* @param aFilename path to INI file * @param aFilename path to INI file
*/ */
nsINIParser(char *aFilename); nsINIParser(const char *aFilename);
~nsINIParser(); ~nsINIParser();
/** /**

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

@ -362,10 +362,7 @@ nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
nsCAutoString path; nsCAutoString path;
operaPrefs->GetNativePath(path); operaPrefs->GetNativePath(path);
char* pathCopy = ToNewCString(path); nsINIParser* parser = new nsINIParser(path.get());
if (!pathCopy)
return NS_ERROR_OUT_OF_MEMORY;
nsINIParser* parser = new nsINIParser(pathCopy);
if (!parser) if (!parser)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@ -394,28 +391,29 @@ nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
nsCRT::free(colorString); nsCRT::free(colorString);
} }
else { else {
char* val = nsnull; nsXPIDLCString val;
PRInt32 err = parser->GetStringAlloc(lastSectionName, transform->keyName, &val, &length); PRInt32 err = parser->GetStringAlloc(lastSectionName, transform->keyName, getter_Copies(val), &length);
if (err == nsINIParser::OK) { if (err == nsINIParser::OK) {
nsCAutoString valStr;
PRInt32 strerr; PRInt32 strerr;
switch (transform->type) { switch (transform->type) {
case _OPM(STRING): case _OPM(STRING):
transform->stringValue = val; transform->stringValue = ToNewCString(val);
break; break;
case _OPM(INT): case _OPM(INT):
valStr = val; transform->intValue = val.ToInteger(&strerr);
transform->intValue = valStr.ToInteger(&strerr);
break; break;
case _OPM(BOOL): case _OPM(BOOL):
valStr = val; transform->boolValue = val.ToInteger(&strerr) != 0;
transform->boolValue = valStr.ToInteger(&strerr) != 0;
break; break;
default: default:
break; break;
} }
transform->prefHasValue = PR_TRUE; transform->prefHasValue = PR_TRUE;
transform->prefSetterFunc(transform, branch); transform->prefSetterFunc(transform, branch);
if (transform->stringValue) {
nsCRT::free(transform->stringValue);
transform->stringValue = nsnull;
}
} }
} }
} }
@ -427,9 +425,6 @@ nsOperaProfileMigrator::CopyPreferences(PRBool aReplace)
if (aReplace) if (aReplace)
CopyUserContentSheet(parser); CopyUserContentSheet(parser);
nsCRT::free(pathCopy);
pathCopy = nsnull;
delete parser; delete parser;
parser = nsnull; parser = nsnull;
@ -457,30 +452,30 @@ nsOperaProfileMigrator::CopyProxySettings(nsINIParser* aParser,
} }
sprintf(serverBuf, "%s Server", protocols[i]); sprintf(serverBuf, "%s Server", protocols[i]);
char* proxyServer = nsnull; nsXPIDLCString proxyServer;
err = aParser->GetStringAlloc("Proxy", serverBuf, &proxyServer, &length); err = aParser->GetStringAlloc("Proxy", serverBuf, getter_Copies(proxyServer), &length);
if (err != nsINIParser::OK) if (err != nsINIParser::OK)
continue; continue;
sprintf(serverPrefBuf, "network.proxy.%s", protocols_l[i]); sprintf(serverPrefBuf, "network.proxy.%s", protocols_l[i]);
sprintf(serverPortPrefBuf, "network.proxy.%s_port", protocols_l[i]); sprintf(serverPortPrefBuf, "network.proxy.%s_port", protocols_l[i]);
SetProxyPref(nsDependentCString(proxyServer), serverPrefBuf, serverPortPrefBuf, aBranch); SetProxyPref(proxyServer, serverPrefBuf, serverPortPrefBuf, aBranch);
} }
GetInteger(aParser, "Proxy", "Use Automatic Proxy Configuration", &enabled); GetInteger(aParser, "Proxy", "Use Automatic Proxy Configuration", &enabled);
if (enabled) if (enabled)
networkProxyType = 2; networkProxyType = 2;
char* configURL = nsnull; nsXPIDLCString configURL;
err = aParser->GetStringAlloc("Proxy", "Automatic Proxy Configuration URL", &configURL, &length); err = aParser->GetStringAlloc("Proxy", "Automatic Proxy Configuration URL", getter_Copies(configURL), &length);
if (err == nsINIParser::OK) if (err == nsINIParser::OK)
aBranch->SetCharPref("network.proxy.autoconfig_url", configURL); aBranch->SetCharPref("network.proxy.autoconfig_url", configURL);
GetInteger(aParser, "Proxy", "No Proxy Servers Check", &enabled); GetInteger(aParser, "Proxy", "No Proxy Servers Check", &enabled);
if (enabled) { if (enabled) {
char* servers = nsnull; nsXPIDLCString servers;
err = aParser->GetStringAlloc("Proxy", "No Proxy Servers", &servers, &length); err = aParser->GetStringAlloc("Proxy", "No Proxy Servers", getter_Copies(servers), &length);
if (err == nsINIParser::OK) if (err == nsINIParser::OK)
ParseOverrideServers(servers, aBranch); ParseOverrideServers(servers.get(), aBranch);
} }
aBranch->SetIntPref("network.proxy.type", networkProxyType); aBranch->SetIntPref("network.proxy.type", networkProxyType);
@ -535,16 +530,16 @@ nsOperaProfileMigrator::CopyUserContentSheet(nsINIParser* aParser)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
char* userContentCSS = nsnull; nsXPIDLCString userContentCSS;
PRInt32 size; PRInt32 size;
PRInt32 err = aParser->GetStringAlloc("User Prefs", "Local CSS File", &userContentCSS, &size); PRInt32 err = aParser->GetStringAlloc("User Prefs", "Local CSS File", getter_Copies(userContentCSS), &size);
if (err == nsINIParser::OK && userContentCSS) { if (err == nsINIParser::OK && userContentCSS.Length() > 0) {
// Copy the file // Copy the file
nsCOMPtr<nsILocalFile> userContentCSSFile(do_CreateInstance("@mozilla.org/file/local;1")); nsCOMPtr<nsILocalFile> userContentCSSFile(do_CreateInstance("@mozilla.org/file/local;1"));
if (!userContentCSSFile) if (!userContentCSSFile)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
userContentCSSFile->InitWithNativePath(nsDependentCString(userContentCSS)); userContentCSSFile->InitWithNativePath(userContentCSS);
PRBool exists; PRBool exists;
userContentCSSFile->Exists(&exists); userContentCSSFile->Exists(&exists);
if (!exists) if (!exists)
@ -1014,18 +1009,18 @@ nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
PRInt32 sectionIndex = 1; PRInt32 sectionIndex = 1;
char section[35]; char section[35];
char *name = nsnull, *url = nsnull, *keyword = nsnull; nsXPIDLCString name, url, keyword;
PRInt32 keyValueLength = 0; PRInt32 keyValueLength = 0;
do { do {
sprintf(section, "Search Engine %d", sectionIndex++); sprintf(section, "Search Engine %d", sectionIndex++);
PRInt32 err = parser->GetStringAlloc(section, "Name", &name, &keyValueLength); PRInt32 err = parser->GetStringAlloc(section, "Name", getter_Copies(name), &keyValueLength);
if (err != nsINIParser::OK) if (err != nsINIParser::OK)
break; break;
err = parser->GetStringAlloc(section, "URL", &url, &keyValueLength); err = parser->GetStringAlloc(section, "URL", getter_Copies(url), &keyValueLength);
if (err != nsINIParser::OK) if (err != nsINIParser::OK)
continue; continue;
err = parser->GetStringAlloc(section, "Key", &keyword, &keyValueLength); err = parser->GetStringAlloc(section, "Key", getter_Copies(keyword), &keyValueLength);
if (err != nsINIParser::OK) if (err != nsINIParser::OK)
continue; continue;
@ -1034,9 +1029,7 @@ nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
if (post) if (post)
continue; continue;
if (nsDependentCString(url).IsEmpty() || if (url.IsEmpty() || keyword.IsEmpty() || name.IsEmpty())
nsDependentCString(keyword).IsEmpty() ||
nsDependentCString(name).IsEmpty())
continue; continue;
nsAutoString nameStr; nameStr.Assign(NS_ConvertUTF8toUCS2(name)); nsAutoString nameStr; nameStr.Assign(NS_ConvertUTF8toUCS2(name));
@ -1061,7 +1054,7 @@ nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
nsCOMPtr<nsIRDFResource> itemRes; nsCOMPtr<nsIRDFResource> itemRes;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), url); NS_NewURI(getter_AddRefs(uri), url.get());
if (!uri) if (!uri)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
nsCAutoString hostCStr; nsCAutoString hostCStr;
@ -1074,7 +1067,7 @@ nsOperaProfileMigrator::CopySmartKeywords(nsIBookmarksService* aBMS,
descStrings, 2, getter_Copies(keywordDesc)); descStrings, 2, getter_Copies(keywordDesc));
rv = aBMS->CreateBookmarkInContainer(nameStr.get(), rv = aBMS->CreateBookmarkInContainer(nameStr.get(),
url, url.get(),
NS_ConvertUTF8toUCS2(keyword).get(), NS_ConvertUTF8toUCS2(keyword).get(),
keywordDesc.get(), keywordDesc.get(),
nsnull, nsnull,
@ -1319,11 +1312,11 @@ void SetProxyPref(const nsACString& aHostPort, const char* aPref,
} }
} }
void ParseOverrideServers(char* aServers, nsIPrefBranch* aBranch) void ParseOverrideServers(const char* aServers, nsIPrefBranch* aBranch)
{ {
// First check to see if the value is "<local>", if so, set the field to // First check to see if the value is "<local>", if so, set the field to
// "localhost,127.0.0.1" // "localhost,127.0.0.1"
nsCAutoString override; override = (char*)aServers; nsCAutoString override; override = aServers;
if (override.Equals("<local>")) { if (override.Equals("<local>")) {
aBranch->SetCharPref("network.proxy.no_proxies_on", "localhost,127.0.0.1"); aBranch->SetCharPref("network.proxy.no_proxies_on", "localhost,127.0.0.1");
} }