* Added "is_in_socket_list" member to determine whether the socket is in the

sSocketList or not (to see if it has to be removed when the socket is
  deleted).
* This fixes the bug reported by Romain when trying to open an unsupported
  protocol (like AF_INET6). Thanks!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30188 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-04-16 08:37:00 +00:00
parent 8a3c8a66b3
commit ddd8303099
@@ -62,6 +62,7 @@ struct net_socket_private : net_socket,
mutex lock; mutex lock;
bool is_connected; bool is_connected;
bool is_in_socket_list;
}; };
@@ -82,7 +83,8 @@ net_socket_private::net_socket_private()
max_backlog(0), max_backlog(0),
child_count(0), child_count(0),
select_pool(NULL), select_pool(NULL),
is_connected(false) is_connected(false),
is_in_socket_list(false)
{ {
first_protocol = NULL; first_protocol = NULL;
first_info = NULL; first_info = NULL;
@@ -111,9 +113,10 @@ net_socket_private::~net_socket_private()
if (parent != NULL) if (parent != NULL)
panic("socket still has a parent!"); panic("socket still has a parent!");
mutex_lock(&sSocketLock); if (is_in_socket_list) {
sSocketList.Remove(this); MutexLocker _(sSocketLock);
mutex_unlock(&sSocketLock); sSocketList.Remove(this);
}
mutex_lock(&lock); mutex_lock(&lock);
@@ -135,6 +138,8 @@ net_socket_private::~net_socket_private()
void void
net_socket_private::RemoveFromParent() net_socket_private::RemoveFromParent()
{ {
ASSERT(!is_in_socket_list && parent != NULL);
parent->RemoveReference(); parent->RemoveReference();
parent = NULL; parent = NULL;
@@ -142,6 +147,8 @@ net_socket_private::RemoveFromParent()
sSocketList.Add(this); sSocketList.Add(this);
mutex_unlock(&sSocketLock); mutex_unlock(&sSocketLock);
is_in_socket_list = true;
RemoveReference(); RemoveReference();
} }
@@ -383,6 +390,7 @@ socket_open(int family, int type, int protocol, net_socket** _socket)
} }
socket->owner = team_get_current_team_id(); socket->owner = team_get_current_team_id();
socket->is_in_socket_list = true;
mutex_lock(&sSocketLock); mutex_lock(&sSocketLock);
sSocketList.Add(socket); sSocketList.Add(socket);