kill off some nsISupportsArray and fix a potential leak. Bug 177400,

r=dmose, sr=alecf
This commit is contained in:
bzbarsky%mit.edu 2002-11-16 02:35:20 +00:00
Родитель 5dd7ed8483
Коммит 18b2f96e55
2 изменённых файлов: 23 добавлений и 35 удалений

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

@ -74,13 +74,6 @@ nsLDAPServiceEntry::~nsLDAPServiceEntry()
// //
PRBool nsLDAPServiceEntry::Init() PRBool nsLDAPServiceEntry::Init()
{ {
nsresult rv;
rv = NS_NewISupportsArray(getter_AddRefs(mListeners));
if (NS_FAILED(rv)) {
return PR_FALSE;
}
return PR_TRUE; return PR_TRUE;
} }
@ -120,7 +113,7 @@ PRUint32 nsLDAPServiceEntry::GetLeases()
// Get/Set the nsLDAPServer object for this entry. // Get/Set the nsLDAPServer object for this entry.
// //
nsILDAPServer *nsLDAPServiceEntry::GetServer() already_AddRefed<nsILDAPServer> nsLDAPServiceEntry::GetServer()
{ {
nsILDAPServer *server; nsILDAPServer *server;
@ -139,7 +132,7 @@ PRBool nsLDAPServiceEntry::SetServer(nsILDAPServer *aServer)
// Get/Set/Clear the nsLDAPConnection object for this entry. // Get/Set/Clear the nsLDAPConnection object for this entry.
// //
nsILDAPConnection *nsLDAPServiceEntry::GetConnection() already_AddRefed<nsILDAPConnection> nsLDAPServiceEntry::GetConnection()
{ {
nsILDAPConnection *conn; nsILDAPConnection *conn;
@ -153,7 +146,7 @@ void nsLDAPServiceEntry::SetConnection(nsILDAPConnection *aConnection)
// Get/Set the nsLDAPMessage object for this entry (it's a "cache"). // Get/Set the nsLDAPMessage object for this entry (it's a "cache").
// //
nsILDAPMessage *nsLDAPServiceEntry::GetMessage() already_AddRefed<nsILDAPMessage> nsLDAPServiceEntry::GetMessage()
{ {
nsILDAPMessage *message; nsILDAPMessage *message;
@ -170,29 +163,24 @@ void nsLDAPServiceEntry::SetMessage(nsILDAPMessage *aMessage)
// potentially have more than one listener waiting for the connection // potentially have more than one listener waiting for the connection
// to be avilable for consumption. // to be avilable for consumption.
// //
nsILDAPMessageListener *nsLDAPServiceEntry::PopListener() already_AddRefed<nsILDAPMessageListener> nsLDAPServiceEntry::PopListener()
{ {
nsILDAPMessageListener *listener; nsILDAPMessageListener *listener;
PRUint32 count; PRInt32 count = mListeners.Count();
mListeners->Count(&count);
if (!count) { if (!count) {
return 0; return 0;
} }
listener = NS_STATIC_CAST(nsILDAPMessageListener *, listener = mListeners[0];
mListeners->ElementAt(0)); NS_ADDREF(listener); // keep it alive
mListeners->RemoveElementAt(0); mListeners.RemoveObjectAt(0);
return listener; return listener;
} }
PRBool nsLDAPServiceEntry::PushListener(nsILDAPMessageListener *listener) PRBool nsLDAPServiceEntry::PushListener(nsILDAPMessageListener *listener)
{ {
PRBool ret; PRBool ret;
PRUint32 count; ret = mListeners.InsertObjectAt(listener, mListeners.Count());
mListeners->Count(&count);
ret = mListeners->InsertElementAt(listener, count);
return ret; return ret;
} }
@ -402,7 +390,7 @@ NS_IMETHODIMP nsLDAPService::GetServer(const PRUnichar *aKey,
*_retval = 0; *_retval = 0;
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
if (!(*_retval = entry->GetServer())) { if (!(*_retval = entry->GetServer().get())) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -436,8 +424,8 @@ NS_IMETHODIMP nsLDAPService::RequestConnection(const PRUnichar *aKey,
} }
entry->SetTimestamp(); entry->SetTimestamp();
conn = getter_AddRefs(entry->GetConnection()); conn = entry->GetConnection();
message = getter_AddRefs(entry->GetMessage()); message = entry->GetMessage();
} }
if (conn) { if (conn) {
@ -494,7 +482,7 @@ NS_IMETHODIMP nsLDAPService::GetConnection(const PRUnichar *aKey,
} }
entry->SetTimestamp(); entry->SetTimestamp();
entry->IncrementLeases(); entry->IncrementLeases();
if (!(*_retval = entry->GetConnection())){ if (!(*_retval = entry->GetConnection().get())){
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -649,7 +637,7 @@ nsLDAPService::OnLDAPMessage(nsILDAPMessage *aMessage)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
message = getter_AddRefs(entry->GetMessage()); message = entry->GetMessage();
if (message) { if (message) {
// We already have a message, lets keep that one. // We already have a message, lets keep that one.
// //
@ -723,7 +711,7 @@ nsLDAPService::EstablishConnection(nsLDAPServiceEntry *aEntry,
PRUint32 options; PRUint32 options;
nsresult rv; nsresult rv;
server = getter_AddRefs(aEntry->GetServer()); server = aEntry->GetServer();
if (!server) { if (!server) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -796,8 +784,8 @@ nsLDAPService::EstablishConnection(nsLDAPServiceEntry *aEntry,
{ {
nsAutoLock lock(mLock); nsAutoLock lock(mLock);
conn2 = getter_AddRefs(aEntry->GetConnection()); conn2 = aEntry->GetConnection();
message = getter_AddRefs(aEntry->GetMessage()); message = aEntry->GetMessage();
} }
if (conn2) { if (conn2) {

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

@ -35,7 +35,7 @@
#include "nsLDAP.h" #include "nsLDAP.h"
#include "ldap.h" #include "ldap.h"
#include "nsString.h" #include "nsString.h"
#include "nsSupportsArray.h" #include "nsCOMArray.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "nsILDAPService.h" #include "nsILDAPService.h"
#include "nsILDAPMessage.h" #include "nsILDAPMessage.h"
@ -71,16 +71,16 @@ class nsLDAPServiceEntry
inline PRTime GetTimestamp(); inline PRTime GetTimestamp();
inline void SetTimestamp(); inline void SetTimestamp();
inline nsILDAPServer *GetServer(); inline already_AddRefed<nsILDAPServer> GetServer();
inline PRBool SetServer(nsILDAPServer *aServer); inline PRBool SetServer(nsILDAPServer *aServer);
inline nsILDAPConnection *GetConnection(); inline already_AddRefed<nsILDAPConnection> GetConnection();
inline void SetConnection(nsILDAPConnection *aConnection); inline void SetConnection(nsILDAPConnection *aConnection);
inline nsILDAPMessage *GetMessage(); inline already_AddRefed<nsILDAPMessage> GetMessage();
inline void SetMessage(nsILDAPMessage *aMessage); inline void SetMessage(nsILDAPMessage *aMessage);
inline nsILDAPMessageListener *PopListener(); inline already_AddRefed<nsILDAPMessageListener> PopListener();
inline PRBool PushListener(nsILDAPMessageListener *); inline PRBool PushListener(nsILDAPMessageListener *);
inline PRBool IsRebinding(); inline PRBool IsRebinding();
@ -99,7 +99,7 @@ class nsLDAPServiceEntry
nsCOMPtr<nsILDAPMessage> mMessage; nsCOMPtr<nsILDAPMessage> mMessage;
// Array holding all the pending callbacks (listeners) for this entry // Array holding all the pending callbacks (listeners) for this entry
nsCOMPtr<nsISupportsArray> mListeners; nsCOMArray<nsILDAPMessageListener> mListeners;
}; };
// This is the interface we're implementing. // This is the interface we're implementing.