OSDN Git Service

Refactor SockDiagTest in preparation for per-UID SOCK_DESTROY.
[android-x86/system-netd.git] / server / MDnsSdListener.cpp
index 7e16a6c..4becbe8 100644 (file)
@@ -513,8 +513,13 @@ int MDnsSdListener::Handler::runCommand(SocketClient *cli,
 
 MDnsSdListener::Monitor::Monitor() {
     mHead = NULL;
-    pthread_mutex_init(&mHeadMutex, NULL);
+    mLiveCount = 0;
+    mPollFds = NULL;
+    mPollRefs = NULL;
+    mPollSize = 10;
     socketpair(AF_LOCAL, SOCK_STREAM, 0, mCtrlSocketPair);
+    pthread_mutex_init(&mHeadMutex, NULL);
+
     pthread_create(&mThread, NULL, MDnsSdListener::Monitor::threadStart, this);
     pthread_detach(mThread);
 }
@@ -583,10 +588,13 @@ int MDnsSdListener::Monitor::stopService() {
 
 void MDnsSdListener::Monitor::run() {
     int pollCount = 1;
-    mPollSize = 10;
 
     mPollFds = (struct pollfd *)calloc(sizeof(struct pollfd), mPollSize);
     mPollRefs = (DNSServiceRef **)calloc(sizeof(DNSServiceRef *), mPollSize);
+    LOG_ALWAYS_FATAL_IF((mPollFds == NULL), "initial calloc failed on mPollFds with a size of %d",
+            ((int)sizeof(struct pollfd)) * mPollSize);
+    LOG_ALWAYS_FATAL_IF((mPollRefs == NULL), "initial calloc failed on mPollRefs with a size of %d",
+            ((int)sizeof(DNSServiceRef *)) * mPollSize);
 
     mPollFds[0].fd = mCtrlSocketPair[0];
     mPollFds[0].events = POLLIN;
@@ -645,6 +653,10 @@ int MDnsSdListener::Monitor::rescan() {
         free(mPollRefs);
         mPollFds = (struct pollfd *)calloc(sizeof(struct pollfd), mPollSize);
         mPollRefs = (DNSServiceRef **)calloc(sizeof(DNSServiceRef *), mPollSize);
+        LOG_ALWAYS_FATAL_IF((mPollFds == NULL), "calloc failed on mPollFds with a size of %d",
+                ((int)sizeof(struct pollfd)) * mPollSize);
+        LOG_ALWAYS_FATAL_IF((mPollRefs == NULL), "calloc failed on mPollRefs with a size of %d",
+                ((int)sizeof(DNSServiceRef *)) * mPollSize);
     } else {
         memset(mPollFds, 0, sizeof(struct pollfd) * mPollSize);
         memset(mPollRefs, 0, sizeof(DNSServiceRef *) * mPollSize);