mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 172131 FMM, Comments which suggest the wrong (De)Allocator, and Style
r=dougt sr=darin
This commit is contained in:
parent
c030b55eb6
commit
09fcb732df
@ -1272,10 +1272,12 @@ ClassIDWriter(PLDHashTable *table,
|
||||
(className ? className : ""),
|
||||
(location ? location : ""));
|
||||
|
||||
|
||||
PR_Free(cidString);
|
||||
PR_FREEIF(contractID);
|
||||
PR_FREEIF(className);
|
||||
if (contractID)
|
||||
PR_Free(contractID);
|
||||
if (className)
|
||||
PR_Free(className);
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
@ -1660,7 +1662,8 @@ nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
||||
{
|
||||
char *buf = aClass.ToString();
|
||||
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
PR_ASSERT(aResult != nsnull);
|
||||
@ -1736,8 +1739,8 @@ nsComponentManagerImpl::ContractIDToClassID(const char *aContractID, nsCID *aCla
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
||||
("nsComponentManager: ContractIDToClassID(%s)->%s", aContractID,
|
||||
NS_SUCCEEDED(rv) ? buf : "[FAILED]"));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -1766,7 +1769,8 @@ nsComponentManagerImpl::CLSIDToContractID(const nsCID &aClass,
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
||||
("nsComponentManager: CLSIDToContractID(%s)->%s", buf,
|
||||
NS_SUCCEEDED(rv) ? *aContractID : "[FAILED]"));
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -1825,7 +1829,8 @@ nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
||||
("nsComponentManager: CreateInstance(%s) %s", buf,
|
||||
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -2487,8 +2492,8 @@ nsComponentManagerImpl::RegisterFactory(const nsCID &aClass,
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
|
||||
("nsComponentManager: RegisterFactory(%s, %s)", buf,
|
||||
(aContractID ? aContractID : "(null)")));
|
||||
delete [] buf;
|
||||
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
|
||||
@ -2630,8 +2635,6 @@ nsComponentManagerImpl::RegisterComponentCommon(const nsCID &aClass,
|
||||
PRBool aPersist,
|
||||
const char *aType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsIDKey key(aClass);
|
||||
nsAutoMonitor mon(mMon);
|
||||
|
||||
@ -2649,7 +2652,8 @@ nsComponentManagerImpl::RegisterComponentCommon(const nsCID &aClass,
|
||||
buf,
|
||||
contractID ? contractID : "(null)",
|
||||
aRegistryName, aType));
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
if (entry && !aReplace) {
|
||||
@ -2661,7 +2665,7 @@ nsComponentManagerImpl::RegisterComponentCommon(const nsCID &aClass,
|
||||
int typeIndex = GetLoaderType(aType);
|
||||
|
||||
nsCOMPtr<nsIComponentLoader> loader;
|
||||
rv = GetLoaderForType(typeIndex, getter_AddRefs(loader));
|
||||
nsresult rv = GetLoaderForType(typeIndex, getter_AddRefs(loader));
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_ERROR,
|
||||
("\t\tgetting loader for %s FAILED\n", aType));
|
||||
@ -2854,7 +2858,8 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID &aClass,
|
||||
char *buf = aClass.ToString();
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
||||
("nsComponentManager: UnregisterFactory(%s)", buf));
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
nsFactoryEntry *old;
|
||||
@ -2889,11 +2894,11 @@ nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass,
|
||||
char *buf = aClass.ToString();
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
||||
("nsComponentManager: UnregisterComponent(%s)", buf));
|
||||
delete [] buf;
|
||||
if (buf)
|
||||
PR_Free(buf);
|
||||
}
|
||||
|
||||
NS_ENSURE_ARG_POINTER(registryName);
|
||||
nsresult rv=NS_OK;
|
||||
nsFactoryEntry *old;
|
||||
|
||||
// first delete all contract id entries that are registered with this cid.
|
||||
@ -2909,10 +2914,9 @@ nsComponentManagerImpl::UnregisterComponent(const nsCID &aClass,
|
||||
}
|
||||
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
||||
("nsComponentManager: Factory unregister(%s) %s.", registryName,
|
||||
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
||||
("nsComponentManager: Factory unregister(%s) succeeded.", registryName));
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -63,34 +63,34 @@ extern const PRUnichar kIsoLatin1ToUCS2[256];
|
||||
|
||||
// This macro can be used in a class declaration for classes that want
|
||||
// to ensure that their instance memory is zeroed.
|
||||
#define NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW \
|
||||
#define NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW \
|
||||
void* operator new(size_t sz) CPP_THROW_NEW { \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
memset(rv, 0, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
memset(rv, 0, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
}
|
||||
|
||||
// This macro works with the next macro to declare a non-inlined
|
||||
// version of the above.
|
||||
#define NS_DECL_ZEROING_OPERATOR_NEW \
|
||||
void* operator new(size_t sz) CPP_THROW_NEW; \
|
||||
#define NS_DECL_ZEROING_OPERATOR_NEW \
|
||||
void* operator new(size_t sz) CPP_THROW_NEW; \
|
||||
void operator delete(void* ptr);
|
||||
|
||||
#define NS_IMPL_ZEROING_OPERATOR_NEW(_class) \
|
||||
#define NS_IMPL_ZEROING_OPERATOR_NEW(_class) \
|
||||
void* _class::operator new(size_t sz) CPP_THROW_NEW { \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
memset(rv, 0, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void _class::operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
void* rv = ::operator new(sz); \
|
||||
if (rv) { \
|
||||
memset(rv, 0, sz); \
|
||||
} \
|
||||
return rv; \
|
||||
} \
|
||||
void _class::operator delete(void* ptr) { \
|
||||
::operator delete(ptr); \
|
||||
}
|
||||
|
||||
// Freeing helper
|
||||
@ -108,9 +108,10 @@ public:
|
||||
CR='\r' /* Carriage Return */
|
||||
};
|
||||
|
||||
/***
|
||||
/***
|
||||
*** The following nsCRT::mem* functions are no longer
|
||||
*** supported. Please use lib C functions instead.
|
||||
*** supported, please use the corresponding lib C
|
||||
*** functions instead.
|
||||
***
|
||||
*** nsCRT::memcpy()
|
||||
*** nsCRT::memcmp()
|
||||
@ -118,9 +119,9 @@ public:
|
||||
*** nsCRT::memset()
|
||||
*** nsCRT::zero()
|
||||
***
|
||||
*** In addition, the following char* string utilities
|
||||
*** are no longer supported either. Please use lib C
|
||||
*** also. Avoid calling into PL_str* if possible.
|
||||
*** Additionally, the following char* string utilities
|
||||
*** are no longer supported, please use the
|
||||
*** corresponding lib C functions instead.
|
||||
***
|
||||
*** nsCRT::strlen()
|
||||
***
|
||||
@ -152,9 +153,9 @@ public:
|
||||
/// Case-insensitive string comparison with length
|
||||
static PRInt32 strncasecmp(const char* s1, const char* s2, PRUint32 aMaxLen) {
|
||||
PRInt32 result=PRInt32(PL_strncasecmp(s1, s2, aMaxLen));
|
||||
//Egags. PL_strncasecmp is returning *very* negative numbers.
|
||||
//Some folks expect -1,0,1, so let's temper it's enthusiasm.
|
||||
if(result<0)
|
||||
//Egads. PL_strncasecmp is returning *very* negative numbers.
|
||||
//Some folks expect -1,0,1, so let's temper its enthusiasm.
|
||||
if (result<0)
|
||||
result=-1;
|
||||
return result;
|
||||
}
|
||||
@ -182,16 +183,16 @@ public:
|
||||
|
||||
How to use this fancy (thread-safe) version of strtok:
|
||||
|
||||
void main( void ) {
|
||||
printf( "%s\n\nTokens:\n", string );
|
||||
void main(void) {
|
||||
printf("%s\n\nTokens:\n", string);
|
||||
// Establish string and get the first token:
|
||||
char* newStr;
|
||||
token = nsCRT::strtok( string, seps, &newStr );
|
||||
while( token != NULL ) {
|
||||
token = nsCRT::strtok(string, seps, &newStr);
|
||||
while (token != NULL) {
|
||||
// While there are tokens in "string"
|
||||
printf( " %s\n", token );
|
||||
printf(" %s\n", token);
|
||||
// Get next token:
|
||||
token = nsCRT::strtok( newStr, seps, &newStr );
|
||||
token = nsCRT::strtok(newStr, seps, &newStr);
|
||||
}
|
||||
}
|
||||
* WARNING - STRTOK WHACKS str THE FIRST TIME IT IS CALLED *
|
||||
@ -208,10 +209,12 @@ public:
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRUint32 aMaxLen);
|
||||
|
||||
// Note: uses new[] to allocate memory, so you must use delete[] to
|
||||
// free the memory
|
||||
// You must use nsCRT::free(PRUnichar*) to free memory allocated
|
||||
// by nsCRT::strdup(PRUnichar*).
|
||||
static PRUnichar* strdup(const PRUnichar* str);
|
||||
|
||||
// You must use nsCRT::free(PRUnichar*) to free memory allocated
|
||||
// by strndup(PRUnichar*, PRUint32).
|
||||
static PRUnichar* strndup(const PRUnichar* str, PRUint32 len);
|
||||
|
||||
static void free(PRUnichar* str) {
|
||||
|
Loading…
Reference in New Issue
Block a user