зеркало из https://github.com/mozilla/gecko-dev.git
Bug 270215 - Memory leak in wallet_GetLine
r=cbiesinger@gmx.at, sr=darin@meer.net
This commit is contained in:
Родитель
53752ec121
Коммит
33fdda65b6
|
@ -1886,13 +1886,12 @@ static nsresult EnsureSingleSignOnProfileObserver()
|
||||||
static PRInt32
|
static PRInt32
|
||||||
si_ReadLine(nsIInputStream* strm, nsString& lineBuffer)
|
si_ReadLine(nsIInputStream* strm, nsString& lineBuffer)
|
||||||
{
|
{
|
||||||
char* line;
|
nsCAutoString line;
|
||||||
nsresult rv = wallet_GetLine(strm, (const char**)&line);
|
nsresult rv = wallet_GetLine(strm, line);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
CopyUTF8toUTF16(line, lineBuffer);
|
CopyUTF8toUTF16(line, lineBuffer);
|
||||||
nsMemory::Free(line);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,20 +229,14 @@ MOZ_DECL_CTOR_COUNTER(wallet_HelpMac)
|
||||||
class wallet_HelpMac {
|
class wallet_HelpMac {
|
||||||
public:
|
public:
|
||||||
wallet_HelpMac() {
|
wallet_HelpMac() {
|
||||||
item1 = nsnull;
|
|
||||||
item2 = nsnull;
|
|
||||||
item3 = nsnull;
|
|
||||||
MOZ_COUNT_CTOR(wallet_HelpMac);
|
MOZ_COUNT_CTOR(wallet_HelpMac);
|
||||||
}
|
}
|
||||||
~wallet_HelpMac() {
|
~wallet_HelpMac() {
|
||||||
WALLET_FREEIF(item1);
|
|
||||||
WALLET_FREEIF(item2);
|
|
||||||
WALLET_FREEIF(item3);
|
|
||||||
MOZ_COUNT_DTOR(wallet_HelpMac);
|
MOZ_COUNT_DTOR(wallet_HelpMac);
|
||||||
}
|
}
|
||||||
const char* item1;
|
nsCString item1;
|
||||||
const char* item2;
|
nsCString item2;
|
||||||
const char* item3;
|
nsCString item3;
|
||||||
};
|
};
|
||||||
wallet_HelpMac * helpMac;
|
wallet_HelpMac * helpMac;
|
||||||
|
|
||||||
|
@ -1114,13 +1108,14 @@ Wallet_RandomName(char* suffix)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
wallet_GetLine(nsIInputStream* strm, const char** lineCString)
|
wallet_GetLine(nsIInputStream* strm, nsCString &line)
|
||||||
{
|
{
|
||||||
|
line.Truncate();
|
||||||
|
|
||||||
nsCOMPtr<nsILineInputStream> lis(do_QueryInterface(strm));
|
nsCOMPtr<nsILineInputStream> lis(do_QueryInterface(strm));
|
||||||
NS_ENSURE_TRUE(lis, NS_ERROR_UNEXPECTED);
|
NS_ENSURE_TRUE(lis, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
PRBool more;
|
PRBool more;
|
||||||
nsCAutoString line;
|
|
||||||
nsresult rv = lis->ReadLine(line, &more);
|
nsresult rv = lis->ReadLine(line, &more);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -1130,22 +1125,19 @@ wallet_GetLine(nsIInputStream* strm, const char** lineCString)
|
||||||
if (!more && line.IsEmpty())
|
if (!more && line.IsEmpty())
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
*lineCString = ToNewCString(line);
|
return NS_OK;
|
||||||
return *lineCString ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PRBool
|
static PRBool
|
||||||
wallet_GetHeader(nsIInputStream* strm)
|
wallet_GetHeader(nsIInputStream* strm)
|
||||||
{
|
{
|
||||||
const char* format = nsnull;
|
nsCAutoString format;
|
||||||
|
|
||||||
/* format revision number */
|
/* format revision number */
|
||||||
if (NS_FAILED(wallet_GetLine(strm, &format))) {
|
if (NS_FAILED(wallet_GetLine(strm, format))) {
|
||||||
return PR_FALSE;
|
return PR_FALSE;
|
||||||
}
|
}
|
||||||
PRBool rv = !strcmp(format, HEADER_VERSION);
|
return format.EqualsLiteral(HEADER_VERSION);
|
||||||
WALLET_FREEIF(format);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1281,7 +1273,7 @@ wallet_ReadFromFile
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (NS_FAILED(wallet_GetLine(strm, &helpMac->item1))) {
|
if (NS_FAILED(wallet_GetLine(strm, helpMac->item1))) {
|
||||||
/* end of file reached */
|
/* end of file reached */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1289,33 +1281,33 @@ wallet_ReadFromFile
|
||||||
/* Distinguished schema list is a list of single entries, not name/value pairs */
|
/* Distinguished schema list is a list of single entries, not name/value pairs */
|
||||||
if (!PL_strcmp(filename, distinguishedSchemaFileName)) {
|
if (!PL_strcmp(filename, distinguishedSchemaFileName)) {
|
||||||
nsVoidArray* dummy = NULL;
|
nsVoidArray* dummy = NULL;
|
||||||
wallet_WriteToList(helpMac->item1, helpMac->item1, dummy, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), helpMac->item1.get(), dummy, list, PR_FALSE, placement);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(wallet_GetLine(strm, &helpMac->item2))) {
|
if (NS_FAILED(wallet_GetLine(strm, helpMac->item2))) {
|
||||||
/* unexpected end of file reached */
|
/* unexpected end of file reached */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WALLET_NULL(helpMac->item2)) {
|
if (helpMac->item2.IsEmpty()) {
|
||||||
/* the value must have been deleted */
|
/* the value must have been deleted */
|
||||||
nsVoidArray* dummy = NULL;
|
nsVoidArray* dummy = NULL;
|
||||||
wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), helpMac->item2.get(), dummy, list, PR_FALSE, placement);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(wallet_GetLine(strm, &helpMac->item3))) {
|
if (NS_FAILED(wallet_GetLine(strm, helpMac->item3))) {
|
||||||
/* end of file reached */
|
/* end of file reached */
|
||||||
nsVoidArray* dummy = NULL;
|
nsVoidArray* dummy = NULL;
|
||||||
wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), helpMac->item2.get(), dummy, list, PR_FALSE, placement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WALLET_NULL(helpMac->item3)) {
|
if (helpMac->item3.IsEmpty()) {
|
||||||
/* just a pair of values, no need for a sublist */
|
/* just a pair of values, no need for a sublist */
|
||||||
nsVoidArray* dummy = NULL;
|
nsVoidArray* dummy = NULL;
|
||||||
wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), helpMac->item2.get(), dummy, list, PR_FALSE, placement);
|
||||||
} else {
|
} else {
|
||||||
/* need to create a sublist and put item2 and item3 onto it */
|
/* need to create a sublist and put item2 and item3 onto it */
|
||||||
|
|
||||||
|
@ -1328,27 +1320,27 @@ wallet_ReadFromFile
|
||||||
if (!sublist) {
|
if (!sublist) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sublist->item = PL_strdup(helpMac->item2);
|
sublist->item = ToNewCString(helpMac->item2);
|
||||||
itemList->AppendElement(sublist);
|
itemList->AppendElement(sublist);
|
||||||
sublist = new wallet_Sublist;
|
sublist = new wallet_Sublist;
|
||||||
if (!sublist) {
|
if (!sublist) {
|
||||||
delete itemList;
|
delete itemList;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sublist->item = PL_strdup(helpMac->item3);
|
sublist->item = ToNewCString(helpMac->item3);
|
||||||
itemList->AppendElement(sublist);
|
itemList->AppendElement(sublist);
|
||||||
/* add any following items to sublist up to next blank line */
|
/* add any following items to sublist up to next blank line */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* get next item for sublist */
|
/* get next item for sublist */
|
||||||
if (NS_FAILED(wallet_GetLine(strm, &helpMac->item3))) {
|
if (NS_FAILED(wallet_GetLine(strm, helpMac->item3))) {
|
||||||
/* end of file reached */
|
/* end of file reached */
|
||||||
wallet_WriteToList(helpMac->item1, nsnull, itemList, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), nsnull, itemList, list, PR_FALSE, placement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WALLET_NULL(helpMac->item3)) {
|
if (helpMac->item3.IsEmpty()) {
|
||||||
/* blank line reached indicating end of sublist */
|
/* blank line reached indicating end of sublist */
|
||||||
wallet_WriteToList(helpMac->item1, nsnull, itemList, list, PR_FALSE, placement);
|
wallet_WriteToList(helpMac->item1.get(), nsnull, itemList, list, PR_FALSE, placement);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* add item to sublist */
|
/* add item to sublist */
|
||||||
|
@ -1357,7 +1349,7 @@ wallet_ReadFromFile
|
||||||
delete itemList;
|
delete itemList;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sublist->item = PL_strdup(helpMac->item3);
|
sublist->item = ToNewCString(helpMac->item3);
|
||||||
itemList->AppendElement(sublist);
|
itemList->AppendElement(sublist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ extern nsresult
|
||||||
Wallet_Decrypt(const nsString& crypt, nsString& text);
|
Wallet_Decrypt(const nsString& crypt, nsString& text);
|
||||||
|
|
||||||
extern nsresult
|
extern nsresult
|
||||||
wallet_GetLine(nsIInputStream* strm, const char** lineCString);
|
wallet_GetLine(nsIInputStream* strm, nsCString& line);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a line to a stream, including a newline character.
|
* Writes a line to a stream, including a newline character.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче