Merge "Fix fortify_fatal issue during DNSServiceProcessResult()"
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp
index 3903605..3133404 100644
--- a/server/MDnsSdListener.cpp
+++ b/server/MDnsSdListener.cpp
@@ -146,7 +146,7 @@
         return;
     }
     if (VDBG) ALOGD("Stopping %s with ref %p", str, ref);
-    DNSServiceRefDeallocate(*ref);
+    mMonitor->deallocateServiceRef(ref);
     mMonitor->freeServiceRef(requestId);
     char *msg;
     asprintf(&msg, "%s stopped", str);
@@ -610,7 +610,9 @@
                         ALOGD("Monitor found [%d].revents = %d - calling ProcessResults",
                                 i, mPollFds[i].revents);
                     }
+                    pthread_mutex_lock(&mHeadMutex);
                     DNSServiceProcessResult(*(mPollRefs[i]));
+                    pthread_mutex_unlock(&mHeadMutex);
                     mPollFds[i].revents = 0;
                 }
             }
@@ -763,3 +765,9 @@
     }
     pthread_mutex_unlock(&mHeadMutex);
 }
+
+void MDnsSdListener::Monitor::deallocateServiceRef(DNSServiceRef* ref) {
+    pthread_mutex_lock(&mHeadMutex);
+    DNSServiceRefDeallocate(*ref);
+    pthread_mutex_unlock(&mHeadMutex);
+}
\ No newline at end of file
diff --git a/server/MDnsSdListener.h b/server/MDnsSdListener.h
index bdf5d0c..1d613f9 100644
--- a/server/MDnsSdListener.h
+++ b/server/MDnsSdListener.h
@@ -79,8 +79,9 @@
         int startService();
         int stopService();
         void run();
+        void deallocateServiceRef(DNSServiceRef* ref);
 
-    private:
+      private:
         int rescan(); // returns the number of elements in the poll
         class Element {
         public: