fixed potential invalid pointer dereference
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Jan 2014 19:56:36 +0000 (21:56 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 30 Jan 2014 19:59:18 +0000 (21:59 +0200)
src/server/core/np.cpp

index f6514e3..f807230 100644 (file)
@@ -376,7 +376,7 @@ static bool HostIsReachable(UINT32 ipAddr, UINT32 zoneId, bool fullCheck, SNMP_T
                return true;
 
        // *** SNMP ***
-       SNMP_Transport *pTransport;
+       SNMP_Transport *pTransport = NULL;
        if (snmpProxy != 0)
        {
                Node *proxyNode = (Node *)g_idxNodeById.get(snmpProxy);
@@ -396,24 +396,27 @@ static bool HostIsReachable(UINT32 ipAddr, UINT32 zoneId, bool fullCheck, SNMP_T
                pTransport = new SNMP_UDPTransport;
                ((SNMP_UDPTransport *)pTransport)->createUDPTransport(NULL, htonl(ipAddr), 161);
        }
-       int version;
-   StringList oids;
-   oids.add(_T(".1.3.6.1.2.1.1.2.0"));
-   oids.add(_T(".1.3.6.1.2.1.1.1.0"));
-   AddDriverSpecificOids(&oids);
-   SNMP_SecurityContext *ctx = SnmpCheckCommSettings(pTransport, &version, NULL, &oids);
-       if (ctx != NULL)
-       {
-               delete ctx;
-               if (transport != NULL)
-               {
-                       pTransport->setSnmpVersion(version);
-                       *transport = pTransport;
-                       pTransport = NULL;      // prevent deletion
-               }
-               reachable = true;
-       }
-       delete pTransport;
+   if (pTransport != NULL)
+   {
+          int version;
+      StringList oids;
+      oids.add(_T(".1.3.6.1.2.1.1.2.0"));
+      oids.add(_T(".1.3.6.1.2.1.1.1.0"));
+      AddDriverSpecificOids(&oids);
+      SNMP_SecurityContext *ctx = SnmpCheckCommSettings(pTransport, &version, NULL, &oids);
+          if (ctx != NULL)
+          {
+                  delete ctx;
+                  if (transport != NULL)
+                  {
+                          pTransport->setSnmpVersion(version);
+                          *transport = pTransport;
+                          pTransport = NULL;   // prevent deletion
+                  }
+                  reachable = true;
+          }
+          delete pTransport;
+   }
 
        return reachable;
 }