mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Fix allocator abuses: bug 331165 r+sr=bsmedberg; bug 484309 r+sr=bsmedberg; bug 484312 r+sr=biesi
This commit is contained in:
parent
bd4e61360d
commit
a3cb4f1f32
@ -785,7 +785,7 @@ nsStandardURL::AppendToSubstring(PRUint32 pos,
|
||||
if (tailLen < 0)
|
||||
tailLen = strlen(tail);
|
||||
|
||||
char *result = (char *) malloc(len + tailLen + 1);
|
||||
char *result = (char *) NS_Alloc(len + tailLen + 1);
|
||||
if (result) {
|
||||
memcpy(result, mSpec.get() + pos, len);
|
||||
memcpy(result + len, tail, tailLen);
|
||||
@ -1669,9 +1669,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
} else
|
||||
relpathLen = flat.Length();
|
||||
|
||||
// XXX hack hack hack
|
||||
char *p = nsnull;
|
||||
char **result = &p;
|
||||
char *result = nsnull;
|
||||
|
||||
LOG(("nsStandardURL::Resolve [this=%p spec=%s relpath=%s]\n",
|
||||
this, mSpec.get(), relpath));
|
||||
@ -1725,7 +1723,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
"://",3) == 0) {
|
||||
// now this is really absolute
|
||||
// because a :// follows the scheme
|
||||
*result = nsCRT::strdup(relpath);
|
||||
result = NS_strdup(relpath);
|
||||
} else {
|
||||
// This is a deprecated form of relative urls like
|
||||
// http:file or http:/path/file
|
||||
@ -1736,7 +1734,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
} else {
|
||||
// the schemes are not the same, we are also done
|
||||
// because we have to assume this is absolute
|
||||
*result = nsCRT::strdup(relpath);
|
||||
result = NS_strdup(relpath);
|
||||
}
|
||||
} else {
|
||||
// add some flags to coalesceFlag if it is an ftp-url
|
||||
@ -1748,7 +1746,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
}
|
||||
if (relpath[0] == '/' && relpath[1] == '/') {
|
||||
// this URL //host/path is almost absolute
|
||||
*result = AppendToSubstring(mScheme.mPos, mScheme.mLen + 1, relpath);
|
||||
result = AppendToSubstring(mScheme.mPos, mScheme.mLen + 1, relpath);
|
||||
} else {
|
||||
// then it must be relative
|
||||
relative = PR_TRUE;
|
||||
@ -1796,27 +1794,25 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
||||
len = mDirectory.mPos + mDirectory.mLen;
|
||||
}
|
||||
}
|
||||
*result = AppendToSubstring(0, len, realrelpath);
|
||||
result = AppendToSubstring(0, len, realrelpath);
|
||||
// locate result path
|
||||
resultPath = *result + mPath.mPos;
|
||||
resultPath = result + mPath.mPos;
|
||||
}
|
||||
if (!*result)
|
||||
if (!result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (resultPath)
|
||||
net_CoalesceDirs(coalesceFlag, resultPath);
|
||||
else {
|
||||
// locate result path
|
||||
resultPath = PL_strstr(*result, "://");
|
||||
resultPath = PL_strstr(result, "://");
|
||||
if (resultPath) {
|
||||
resultPath = PL_strchr(resultPath + 3, '/');
|
||||
if (resultPath)
|
||||
net_CoalesceDirs(coalesceFlag,resultPath);
|
||||
}
|
||||
}
|
||||
// XXX avoid extra copy
|
||||
out = *result;
|
||||
free(*result);
|
||||
out.Adopt(result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
2
netwerk/cache/src/nsDiskCacheMap.cpp
vendored
2
netwerk/cache/src/nsDiskCacheMap.cpp
vendored
@ -1034,7 +1034,7 @@ nsresult
|
||||
nsDiskCacheMap::EnsureBuffer(PRUint32 bufSize)
|
||||
{
|
||||
if (mBufferSize < bufSize) {
|
||||
char * buf = (char *)realloc(mBuffer, bufSize);
|
||||
char * buf = (char *)PR_REALLOC(mBuffer, bufSize);
|
||||
if (!buf) {
|
||||
mBufferSize = 0;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -41,13 +41,13 @@
|
||||
static void*
|
||||
CloneCString(nsHashKey *aKey, void *aData, void* closure)
|
||||
{
|
||||
return nsCRT::strdup((const char*)aData);
|
||||
return NS_strdup((const char*)aData);
|
||||
}
|
||||
|
||||
static PRBool
|
||||
DeleteCString(nsHashKey *aKey, void *aData, void* closure)
|
||||
{
|
||||
nsCRT::free((char*)aData);
|
||||
NS_Free(aData);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ nsInt2StrHashtable::nsInt2StrHashtable()
|
||||
nsresult
|
||||
nsInt2StrHashtable::Put(PRUint32 key, const char* aData)
|
||||
{
|
||||
char* value = nsCRT::strdup(aData);
|
||||
char* value = NS_strdup(aData);
|
||||
if (value == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsPRUint32Key k(key);
|
||||
@ -76,7 +76,7 @@ nsInt2StrHashtable::Get(PRUint32 key)
|
||||
const char* value = (const char*)mHashtable.Get(&k);
|
||||
if (value == nsnull)
|
||||
return nsnull;
|
||||
return nsCRT::strdup(value);
|
||||
return NS_strdup(value);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -276,7 +276,7 @@ CategoryNode::GetLeaf(const char* aEntryName,
|
||||
|
||||
// we only want the non-persistent value
|
||||
if (ent && ent->nonpValue) {
|
||||
*_retval = nsCRT::strdup(ent->nonpValue);
|
||||
*_retval = NS_strdup(ent->nonpValue);
|
||||
if (*_retval)
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
@ -1164,9 +1164,9 @@ ClassIDWriter(PLDHashTable *table,
|
||||
(location ? location : ""));
|
||||
|
||||
if (contractID)
|
||||
PR_Free(contractID);
|
||||
NS_Free(contractID);
|
||||
if (className)
|
||||
PR_Free(className);
|
||||
NS_Free(className);
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
@ -36,8 +36,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsID.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
static const char gIDFormat[] =
|
||||
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
|
||||
@ -122,13 +121,13 @@ PRBool nsID::Parse(const char *aIDStr)
|
||||
|
||||
/*
|
||||
* Returns an allocated string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||
* format. The string is allocated with PR_Malloc and should be freed by
|
||||
* format. The string is allocated with NS_Alloc and should be freed by
|
||||
* the caller.
|
||||
*/
|
||||
|
||||
char *nsID::ToString() const
|
||||
{
|
||||
char *res = (char*)PR_Malloc(NSID_LENGTH); // use PR_Malloc if this is to be freed with nsCRT::free
|
||||
char *res = (char*)NS_Alloc(NSID_LENGTH);
|
||||
|
||||
if (res != NULL) {
|
||||
PR_snprintf(res, NSID_LENGTH, gIDFormat,
|
||||
|
Loading…
Reference in New Issue
Block a user