libsysutils: Fix bug where we'd leak our control pipes when closing down a listener
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
8d3fc3fde3
commit
dbdb0db516
1 changed files with 3 additions and 7 deletions
|
|
@ -83,13 +83,13 @@ int SocketListener::stopListener() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGD("Signaled listener thread - waiting for it to die");
|
|
||||||
void *ret;
|
void *ret;
|
||||||
if (pthread_join(mThread, &ret)) {
|
if (pthread_join(mThread, &ret)) {
|
||||||
LOGE("Error joining to listener thread (%s)", strerror(errno));
|
LOGE("Error joining to listener thread (%s)", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOGD("Listener stopped");
|
close(mCtrlPipe[0]);
|
||||||
|
close(mCtrlPipe[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,6 @@ void *SocketListener::threadStart(void *obj) {
|
||||||
SocketListener *me = reinterpret_cast<SocketListener *>(obj);
|
SocketListener *me = reinterpret_cast<SocketListener *>(obj);
|
||||||
|
|
||||||
me->runListener();
|
me->runListener();
|
||||||
LOGD("Listener thread shutting down");
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -143,10 +142,8 @@ void SocketListener::runListener() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(mCtrlPipe[0], &read_fds)) {
|
if (FD_ISSET(mCtrlPipe[0], &read_fds))
|
||||||
LOGD("Control message received");
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (mListen && FD_ISSET(mSock, &read_fds)) {
|
if (mListen && FD_ISSET(mSock, &read_fds)) {
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
socklen_t alen = sizeof(addr);
|
socklen_t alen = sizeof(addr);
|
||||||
|
|
@ -157,7 +154,6 @@ void SocketListener::runListener() {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
LOGD("SocketListener client connection accepted");
|
|
||||||
pthread_mutex_lock(&mClientsLock);
|
pthread_mutex_lock(&mClientsLock);
|
||||||
mClients->push_back(new SocketClient(c));
|
mClients->push_back(new SocketClient(c));
|
||||||
pthread_mutex_unlock(&mClientsLock);
|
pthread_mutex_unlock(&mClientsLock);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue