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

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

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