[IOT-1575] Initialize socket fd after closing session
authorMinji Park <minjii.park@samsung.com>
Thu, 17 Nov 2016 12:21:33 +0000 (21:21 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Mon, 21 Nov 2016 09:20:41 +0000 (09:20 +0000)
- add socket fd initialization after closing TCP session in tcpserver

Change-Id: Icb40f0c37ccc17ee9972974cfeae752e3a60048d
Signed-off-by: Hyuna Jo <hyuna0213.jo@samsung.com>
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14499
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 909af76..681579b 100644 (file)
@@ -310,7 +310,10 @@ static void CASelectReturned(fd_set *readFds)
                 if (FD_ISSET(svritem->fd, readFds))
                 {
                     CAReceiveMessage(svritem->fd);
-                    FD_CLR(svritem->fd, readFds);
+                    if (-1 != svritem->fd)
+                    {
+                        FD_CLR(svritem->fd, readFds);
+                    }
                 }
             }
         }
@@ -1125,6 +1128,7 @@ CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index)
     {
         shutdown(svritem->fd, SHUT_RDWR);
         close(svritem->fd);
+        svritem->fd = -1;
     }
     u_arraylist_remove(caglobals.tcp.svrlist, index);
     OICFree(svritem->data);
@@ -1137,6 +1141,7 @@ CAResult_t CADisconnectTCPSession(CATCPSessionInfo_t *svritem, size_t index)
     }
 
     OICFree(svritem);
+    svritem = NULL;
     return CA_STATUS_OK;
 }