You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2015/08/11 23:18:30 UTC

trafficserver git commit: Coverity issues: making the sanity check calls useful!

Repository: trafficserver
Updated Branches:
  refs/heads/master f65b867bd -> 3d0d2564c


Coverity issues: making the sanity check calls useful!


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/3d0d2564
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/3d0d2564
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/3d0d2564

Branch: refs/heads/master
Commit: 3d0d2564cc91bcb32174f1b8a61d903a30eda8b5
Parents: f65b867
Author: Syeda Persia Aziz <pe...@yahoo.com>
Authored: Mon Jul 20 18:16:17 2015 -0500
Committer: Alan M. Carroll <am...@apache.org>
Committed: Tue Aug 11 16:00:59 2015 -0500

----------------------------------------------------------------------
 iocore/cache/RamCacheCLFUS.cc                   |  2 +
 lib/atscppapi/src/Plugin.cc                     |  3 +-
 lib/ts/ParseRules.cc                            | 83 --------------------
 lib/ts/ParseRules.h                             |  2 -
 mgmt/Alarms.cc                                  |  1 +
 mgmt/LocalManager.cc                            |  2 +-
 mgmt/MultiFile.cc                               |  1 +
 mgmt/api/EventCallback.cc                       | 82 ++++++++++---------
 .../stale_while_revalidate.c                    |  1 +
 proxy/InkAPI.cc                                 | 20 ++---
 proxy/SocksProxy.cc                             |  6 +-
 proxy/congest/CongestionTest.cc                 |  5 ++
 proxy/http/HttpClientSession.cc                 |  2 +-
 proxy/http2/Http2ClientSession.cc               |  1 +
 proxy/logging/Log.cc                            |  1 +
 15 files changed, 72 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/iocore/cache/RamCacheCLFUS.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
index 0e051b2..8eb72ce 100644
--- a/iocore/cache/RamCacheCLFUS.cc
+++ b/iocore/cache/RamCacheCLFUS.cc
@@ -310,6 +310,8 @@ RamCacheCLFUS::tick()
     return;
   e = lru[1].dequeue();
 Lfree:
+  if (!e) // e may be NULL after e= lru[1].dequeue()
+    return;
   e->flag_bits.lru = 0;
   history--;
   uint32_t b = e->key.slice32(3) % nbuckets;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/atscppapi/src/Plugin.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/Plugin.cc b/lib/atscppapi/src/Plugin.cc
index 6de4391..176a030 100644
--- a/lib/atscppapi/src/Plugin.cc
+++ b/lib/atscppapi/src/Plugin.cc
@@ -34,5 +34,6 @@ atscppapi::RegisterGlobalPlugin(std::string name, std::string vendor, std::strin
   info.plugin_name = const_cast<char *>(name.c_str());
   info.vendor_name = const_cast<char *>(vendor.c_str());
   info.support_email = const_cast<char *>(email.c_str());
-  TSPluginRegister(&info);
+  if (TSPluginRegister(&info) != TS_SUCCESS)
+    TSError("[Plugin.cc] Plugin registration failed.");
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ParseRules.cc b/lib/ts/ParseRules.cc
index ffc4a4e..6bd61b7 100644
--- a/lib/ts/ParseRules.cc
+++ b/lib/ts/ParseRules.cc
@@ -41,89 +41,6 @@ const char parseRulesCTypeToLower[256] = {
 #include "ParseRulesCTypeToLower"
 };
 
-unsigned char *
-ParseRules::scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask)
-{
-  unsigned int i;
-  uint32_t *wptr;
-  unsigned char *align_ptr;
-  uintptr_t f_bytes, b_bytes, words, align_off;
-
-  align_off = ((uintptr_t)ptr & 3);
-  align_ptr = (unsigned char *)(((uintptr_t)ptr) & ~3);
-
-  f_bytes = (align_off ? 4 - align_off : 0);
-
-  words = (n - f_bytes) >> 2;
-
-  if (words == 0) {
-    for (i = 0; i < n; i++)
-      if (!is_type(ptr[i], bitmask))
-        return (&ptr[i]);
-  } else {
-    wptr = ((uint32_t *)align_ptr) + (align_off ? 1 : 0);
-    switch (align_off) {
-    case 1:
-      if (!is_type(align_ptr[1], bitmask))
-        return (&ptr[1]);
-    case 2:
-      if (!is_type(align_ptr[2], bitmask))
-        return (&ptr[2]);
-    case 3:
-      if (!is_type(align_ptr[3], bitmask))
-        return (&ptr[3]);
-      break;
-    default:
-      break;
-    }
-
-    b_bytes = n - ((words << 2) + f_bytes);
-
-    for (i = 0; i < words; i++) {
-      uint32_t word = wptr[i];
-      uint32_t result = (is_type(((word >> 0) & 0xFF), bitmask) & is_type(((word >> 8) & 0xFF), bitmask) &
-                         is_type(((word >> 16) & 0xFF), bitmask) & is_type(((word >> 24) & 0xFF), bitmask));
-      if (result == 0) {
-        unsigned char *cptr = (unsigned char *)&(wptr[i]);
-        if (!is_type(cptr[0], bitmask))
-          return (&cptr[0]);
-        if (!is_type(cptr[1], bitmask))
-          return (&cptr[1]);
-        if (!is_type(cptr[2], bitmask))
-          return (&cptr[2]);
-        return (&cptr[3]);
-      }
-    }
-
-    align_ptr = (unsigned char *)&(wptr[words]);
-
-    switch (b_bytes) {
-    case 1:
-      if (!is_type(align_ptr[0], bitmask))
-        return (&align_ptr[0]);
-      break;
-    case 2:
-      if (!is_type(align_ptr[0], bitmask))
-        return (&align_ptr[0]);
-      if (!is_type(align_ptr[1], bitmask))
-        return (&align_ptr[1]);
-      break;
-    case 3:
-      if (!is_type(align_ptr[0], bitmask))
-        return (&align_ptr[0]);
-      if (!is_type(align_ptr[1], bitmask))
-        return (&align_ptr[1]);
-      if (!is_type(align_ptr[2], bitmask))
-        return (&align_ptr[2]);
-      break;
-    default:
-      break;
-    }
-  }
-  return 0;
-}
-
-
 void
 ParseRules::ink_tolower_buffer(char *ptr, unsigned int n)
 {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.h
----------------------------------------------------------------------
diff --git a/lib/ts/ParseRules.h b/lib/ts/ParseRules.h
index 4045b6d..ae248de 100644
--- a/lib/ts/ParseRules.h
+++ b/lib/ts/ParseRules.h
@@ -162,8 +162,6 @@ public:
   static const char *memchr(const char *s, char c, int max_length);
   static const char *strchr(const char *s, char c);
 
-  static unsigned char *scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask);
-
 private:
   ParseRules(const ParseRules &);
   ParseRules &operator=(const ParseRules &);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/Alarms.cc
----------------------------------------------------------------------
diff --git a/mgmt/Alarms.cc b/mgmt/Alarms.cc
index 7bfee8a..3511b70 100644
--- a/mgmt/Alarms.cc
+++ b/mgmt/Alarms.cc
@@ -413,6 +413,7 @@ Alarms::constructAlarmMessage(const AppVersionInfo &version, char *ip, char *mes
       if (max >= 1) {
         message[0] = '\0';
       }
+      ink_mutex_release(&mutex);
       return;
     }
     ink_strlcpy(&message[n], "alarm: none\n", max - n);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/LocalManager.cc
----------------------------------------------------------------------
diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
index 30f8cac..9d41a8a 100644
--- a/mgmt/LocalManager.cc
+++ b/mgmt/LocalManager.cc
@@ -601,7 +601,7 @@ LocalManager::handleMgmtMsgFromProcesses(MgmtMessageHdr *mh)
                 data_raw);
       break;
     }
-  }
+  } break;
   case MGMT_SIGNAL_LOG_FILES_ROLLED: {
     Debug("lm", "Rolling logs %s", (char *)data_raw);
     break;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/MultiFile.cc
----------------------------------------------------------------------
diff --git a/mgmt/MultiFile.cc b/mgmt/MultiFile.cc
index 9bd04d3..a0c8773 100644
--- a/mgmt/MultiFile.cc
+++ b/mgmt/MultiFile.cc
@@ -125,6 +125,7 @@ MultiFile::WalkFiles(ExpandingArray *fileList)
     } else {
       if (stat(records_config_filePath, &records_config_fileInfo) < 0) {
         delete[] filePath;
+        delete[] records_config_filePath;
         continue;
       }
       // Ignore ., .., and any dot files

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/api/EventCallback.cc
----------------------------------------------------------------------
diff --git a/mgmt/api/EventCallback.cc b/mgmt/api/EventCallback.cc
index f9736d8..c86ad3f 100644
--- a/mgmt/api/EventCallback.cc
+++ b/mgmt/api/EventCallback.cc
@@ -213,18 +213,20 @@ cb_table_register(CallbackTable *cb_table, const char *event_name, TSEventSignal
   } else { // register callback for specific alarm
     // printf("[EventSignalCbRegister] Register callback for %s\n", event_name);
     id = get_event_id(event_name);
-    if (!cb_table->event_callback_l[id]) {
-      cb_table->event_callback_l[id] = create_queue();
-      first_time = 1;
-    }
+    if (id != -1) {
+      if (!cb_table->event_callback_l[id]) {
+        cb_table->event_callback_l[id] = create_queue();
+        first_time = 1;
+      }
 
-    if (!cb_table->event_callback_l[id]) {
-      ink_mutex_release(&cb_table->event_callback_lock);
-      return TS_ERR_SYS_CALL;
+      if (!cb_table->event_callback_l[id]) {
+        ink_mutex_release(&cb_table->event_callback_lock);
+        return TS_ERR_SYS_CALL;
+      }
+      // now add to list
+      event_cb = create_event_callback(func, data);
+      enqueue(cb_table->event_callback_l[id], event_cb);
     }
-    // now add to list
-    event_cb = create_event_callback(func, data);
-    enqueue(cb_table->event_callback_l[id], event_cb);
   }
 
   // release lock on callback table
@@ -301,41 +303,43 @@ cb_table_unregister(CallbackTable *cb_table, const char *event_name, TSEventSign
   } else {
     // unregister for specific event
     int id = get_event_id(event_name);
-    if (cb_table->event_callback_l[id]) {
-      int queue_depth;
-
-      queue_depth = queue_len(cb_table->event_callback_l[id]);
-      // func == NULL means unregister all functions associated with alarm
-      if (func == NULL) {
-        while (!queue_is_empty(cb_table->event_callback_l[id])) {
-          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
-          delete_event_callback(event_cb);
-        }
-
-        // clean up queue and set to NULL
-        delete_queue(cb_table->event_callback_l[id]);
-        cb_table->event_callback_l[id] = NULL;
-      } else {
-        // remove this function
-        for (int j = 0; j < queue_depth; j++) {
-          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
-          cb_fun = event_cb->func;
+    if (id != -1) {
+      if (cb_table->event_callback_l[id]) {
+        int queue_depth;
 
-          // the pointers are the same
-          if (*cb_fun == *func) {
+        queue_depth = queue_len(cb_table->event_callback_l[id]);
+        // func == NULL means unregister all functions associated with alarm
+        if (func == NULL) {
+          while (!queue_is_empty(cb_table->event_callback_l[id])) {
+            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
             delete_event_callback(event_cb);
-            continue;
           }
 
-          enqueue(cb_table->event_callback_l[id], event_cb);
-        }
-
-        // is queue empty now?
-        if (queue_is_empty(cb_table->event_callback_l[id])) {
+          // clean up queue and set to NULL
           delete_queue(cb_table->event_callback_l[id]);
           cb_table->event_callback_l[id] = NULL;
-        }
-      } // end if NULL else
+        } else {
+          // remove this function
+          for (int j = 0; j < queue_depth; j++) {
+            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
+            cb_fun = event_cb->func;
+
+            // the pointers are the same
+            if (*cb_fun == *func) {
+              delete_event_callback(event_cb);
+              continue;
+            }
+
+            enqueue(cb_table->event_callback_l[id], event_cb);
+          }
+
+          // is queue empty now?
+          if (queue_is_empty(cb_table->event_callback_l[id])) {
+            delete_queue(cb_table->event_callback_l[id]);
+            cb_table->event_callback_l[id] = NULL;
+          }
+        } // end if NULL else
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
index 5eab951..c130af4 100644
--- a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
+++ b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
@@ -268,6 +268,7 @@ consume_resource(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED)
   case TS_EVENT_VCONN_WRITE_READY:
     // We shouldn't get here because we specify the exact size of the buffer.
     TSDebug(PLUGIN_NAME, "Write Ready");
+    break;
   case TS_EVENT_VCONN_WRITE_COMPLETE:
     TSDebug(PLUGIN_NAME, "Write Complete");
     // TSDebug(PLUGIN_NAME, "TSVConnShutdown()");

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 6c4129e..f634d52 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -4007,7 +4007,7 @@ TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
 
   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->request_get();
   *obj = reinterpret_cast<TSMLoc>(info->request_get()->m_http);
-  sdk_sanity_check_mbuffer(*bufp);
+  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
 }
 
 
@@ -4018,7 +4018,7 @@ TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
 
   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->response_get();
   *obj = reinterpret_cast<TSMLoc>(info->response_get()->m_http);
-  sdk_sanity_check_mbuffer(*bufp);
+  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
 }
 
 time_t
@@ -4592,7 +4592,7 @@ TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
   if (hptr->valid()) {
     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
-    sdk_sanity_check_mbuffer(*bufp);
+    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
     return TS_SUCCESS;
   }
 
@@ -4613,7 +4613,7 @@ TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
   if (hptr->valid()) {
     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
-    sdk_sanity_check_mbuffer(*bufp);
+    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
     return TS_SUCCESS;
   }
 
@@ -4633,7 +4633,7 @@ TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
   if (hptr->valid()) {
     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
-    sdk_sanity_check_mbuffer(*bufp);
+    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
     return TS_SUCCESS;
   }
 
@@ -4673,7 +4673,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
 
   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
-  sdk_sanity_check_mbuffer(*bufp);
+  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
 
   return TS_SUCCESS;
 }
@@ -4711,7 +4711,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
 
   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
-  sdk_sanity_check_mbuffer(*bufp);
+  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
 
   return TS_SUCCESS;
 }
@@ -4745,7 +4745,7 @@ TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
   ink_assert(c_resp != NULL && c_resp->valid());
   *(reinterpret_cast<HTTPHdr **>(bufp)) = c_resp;
   *obj = reinterpret_cast<TSMLoc>(c_resp->m_http);
-  sdk_sanity_check_mbuffer(*bufp);
+  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
 
   return TS_SUCCESS;
 }
@@ -8671,13 +8671,13 @@ TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response)
   // We allow for either request or response to be empty (or both), in
   // which case we default to the transactions request or response.
   if (request) {
-    sdk_sanity_check_mbuffer(request);
+    sdk_assert(sdk_sanity_check_mbuffer(request) == TS_SUCCESS);
     req = reinterpret_cast<HTTPHdr *>(request);
   } else {
     req = &(sm->t_state.hdr_info.client_request);
   }
   if (response) {
-    sdk_sanity_check_mbuffer(response);
+    sdk_assert(sdk_sanity_check_mbuffer(response) == TS_SUCCESS);
     resp = reinterpret_cast<HTTPHdr *>(response);
   } else {
     resp = &(sm->t_state.hdr_info.server_response);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/SocksProxy.cc
----------------------------------------------------------------------
diff --git a/proxy/SocksProxy.cc b/proxy/SocksProxy.cc
index 9d8d48b..1ff2f78 100644
--- a/proxy/SocksProxy.cc
+++ b/proxy/SocksProxy.cc
@@ -467,9 +467,9 @@ SocksProxy::setupHttpRequest(unsigned char *p)
     // just use the last 4 octets as IPv4 addr:
     a->type = SOCKS_ATYPE_IPV4;
     a->addr.ipv4[0] = p[16];
-    a->addr.ipv4[0] = p[17];
-    a->addr.ipv4[0] = p[18];
-    a->addr.ipv4[0] = p[19];
+    a->addr.ipv4[1] = p[17];
+    a->addr.ipv4[2] = p[18];
+    a->addr.ipv4[3] = p[19];
 
     break;
   default:

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/congest/CongestionTest.cc
----------------------------------------------------------------------
diff --git a/proxy/congest/CongestionTest.cc b/proxy/congest/CongestionTest.cc
index 1e0dcb8..f546f54 100644
--- a/proxy/congest/CongestionTest.cc
+++ b/proxy/congest/CongestionTest.cc
@@ -84,11 +84,13 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
     if (i % 2 == 1 && data == 0) {
       rprintf(t, "verify content failed: key(%d) deleted\n", i);
       *pstatus = REGRESSION_TEST_FAILED;
+      delete htable;
       return;
     }
     if (data != 0 && data != i) {
       rprintf(t, "verify content failed: key(%d) data(%d)\n", i, data);
       *pstatus = REGRESSION_TEST_FAILED;
+      delete htable;
       return;
     }
     if (i % (count / 50) == 0)
@@ -128,6 +130,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
       if (data != htable->lookup_entry(data)) {
         rprintf(t, "verify content failed: key(%d) data(%d)\n", data, htable->lookup_entry(data));
         *pstatus = REGRESSION_TEST_FAILED;
+        delete htable;
         return;
       }
     }
@@ -137,6 +140,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
   if (new_count != 0) {
     rprintf(t, "there are %d extra entries in the table\n", new_count);
     *pstatus = REGRESSION_TEST_FAILED;
+    delete htable;
     return;
   }
 
@@ -157,6 +161,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
   if (new_count != 0) {
     rprintf(t, "there are %d extra entries in the table\n", new_count);
     *pstatus = REGRESSION_TEST_FAILED;
+    delete htable;
     return;
   }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http/HttpClientSession.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpClientSession.cc b/proxy/http/HttpClientSession.cc
index f02834c..0ba1e54 100644
--- a/proxy/http/HttpClientSession.cc
+++ b/proxy/http/HttpClientSession.cc
@@ -313,7 +313,7 @@ HttpClientSession::do_io_close(int alerrno)
     if (ssl_vc) {
       ssl_vc->set_ssl_iobuf(NULL);
     }
-    if (upgrade_to_h2c) {
+    if (upgrade_to_h2c && this->current_reader) {
       Http2ClientSession *h2_session = http2ClientSessionAllocator.alloc();
 
       h2_session->set_upgrade_context(&current_reader->t_state.hdr_info.client_request);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http2/Http2ClientSession.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
index 0ea6fca..386195b 100644
--- a/proxy/http2/Http2ClientSession.cc
+++ b/proxy/http2/Http2ClientSession.cc
@@ -138,6 +138,7 @@ Http2ClientSession::set_upgrade_context(HTTPHdr *h)
   upgrade_context.req_header->copy(h);
 
   MIMEField *settings = upgrade_context.req_header->field_find(MIME_FIELD_HTTP2_SETTINGS, MIME_LEN_HTTP2_SETTINGS);
+  ink_release_assert(settings != NULL);
   int svlen;
   const char *sv = settings->value_get(&svlen);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/logging/Log.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 598ec6b..03ef392 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -1432,6 +1432,7 @@ Log::match_logobject(LogBufferHeader *header)
         obj = NULL;
       }
     }
+    delete fmt;
   }
   return obj;
 }


Re: trafficserver git commit: Coverity issues: making the sanity check calls useful!

Posted by James Peach <jp...@apache.org>.
This has multiple, independent changes, so it should have been a series of separate commits. I think it is also worth referencing the Coverity CID (I assume that this fixes a number of them?)


> On Aug 11, 2015, at 2:18 PM, amc@apache.org wrote:
> 
> Repository: trafficserver
> Updated Branches:
>  refs/heads/master f65b867bd -> 3d0d2564c
> 
> 
> Coverity issues: making the sanity check calls useful!
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/3d0d2564
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/3d0d2564
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/3d0d2564
> 
> Branch: refs/heads/master
> Commit: 3d0d2564cc91bcb32174f1b8a61d903a30eda8b5
> Parents: f65b867
> Author: Syeda Persia Aziz <pe...@yahoo.com>
> Authored: Mon Jul 20 18:16:17 2015 -0500
> Committer: Alan M. Carroll <am...@apache.org>
> Committed: Tue Aug 11 16:00:59 2015 -0500
> 
> ----------------------------------------------------------------------
> iocore/cache/RamCacheCLFUS.cc                   |  2 +
> lib/atscppapi/src/Plugin.cc                     |  3 +-
> lib/ts/ParseRules.cc                            | 83 --------------------
> lib/ts/ParseRules.h                             |  2 -
> mgmt/Alarms.cc                                  |  1 +
> mgmt/LocalManager.cc                            |  2 +-
> mgmt/MultiFile.cc                               |  1 +
> mgmt/api/EventCallback.cc                       | 82 ++++++++++---------
> .../stale_while_revalidate.c                    |  1 +
> proxy/InkAPI.cc                                 | 20 ++---
> proxy/SocksProxy.cc                             |  6 +-
> proxy/congest/CongestionTest.cc                 |  5 ++
> proxy/http/HttpClientSession.cc                 |  2 +-
> proxy/http2/Http2ClientSession.cc               |  1 +
> proxy/logging/Log.cc                            |  1 +
> 15 files changed, 72 insertions(+), 140 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/iocore/cache/RamCacheCLFUS.cc
> ----------------------------------------------------------------------
> diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
> index 0e051b2..8eb72ce 100644
> --- a/iocore/cache/RamCacheCLFUS.cc
> +++ b/iocore/cache/RamCacheCLFUS.cc
> @@ -310,6 +310,8 @@ RamCacheCLFUS::tick()
>     return;
>   e = lru[1].dequeue();
> Lfree:
> +  if (!e) // e may be NULL after e= lru[1].dequeue()
> +    return;
>   e->flag_bits.lru = 0;
>   history--;
>   uint32_t b = e->key.slice32(3) % nbuckets;
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/atscppapi/src/Plugin.cc
> ----------------------------------------------------------------------
> diff --git a/lib/atscppapi/src/Plugin.cc b/lib/atscppapi/src/Plugin.cc
> index 6de4391..176a030 100644
> --- a/lib/atscppapi/src/Plugin.cc
> +++ b/lib/atscppapi/src/Plugin.cc
> @@ -34,5 +34,6 @@ atscppapi::RegisterGlobalPlugin(std::string name, std::string vendor, std::strin
>   info.plugin_name = const_cast<char *>(name.c_str());
>   info.vendor_name = const_cast<char *>(vendor.c_str());
>   info.support_email = const_cast<char *>(email.c_str());
> -  TSPluginRegister(&info);
> +  if (TSPluginRegister(&info) != TS_SUCCESS)
> +    TSError("[Plugin.cc] Plugin registration failed.");
> }
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.cc
> ----------------------------------------------------------------------
> diff --git a/lib/ts/ParseRules.cc b/lib/ts/ParseRules.cc
> index ffc4a4e..6bd61b7 100644
> --- a/lib/ts/ParseRules.cc
> +++ b/lib/ts/ParseRules.cc
> @@ -41,89 +41,6 @@ const char parseRulesCTypeToLower[256] = {
> #include "ParseRulesCTypeToLower"
> };
> 
> -unsigned char *
> -ParseRules::scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask)
> -{
> -  unsigned int i;
> -  uint32_t *wptr;
> -  unsigned char *align_ptr;
> -  uintptr_t f_bytes, b_bytes, words, align_off;
> -
> -  align_off = ((uintptr_t)ptr & 3);
> -  align_ptr = (unsigned char *)(((uintptr_t)ptr) & ~3);
> -
> -  f_bytes = (align_off ? 4 - align_off : 0);
> -
> -  words = (n - f_bytes) >> 2;
> -
> -  if (words == 0) {
> -    for (i = 0; i < n; i++)
> -      if (!is_type(ptr[i], bitmask))
> -        return (&ptr[i]);
> -  } else {
> -    wptr = ((uint32_t *)align_ptr) + (align_off ? 1 : 0);
> -    switch (align_off) {
> -    case 1:
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&ptr[1]);
> -    case 2:
> -      if (!is_type(align_ptr[2], bitmask))
> -        return (&ptr[2]);
> -    case 3:
> -      if (!is_type(align_ptr[3], bitmask))
> -        return (&ptr[3]);
> -      break;
> -    default:
> -      break;
> -    }
> -
> -    b_bytes = n - ((words << 2) + f_bytes);
> -
> -    for (i = 0; i < words; i++) {
> -      uint32_t word = wptr[i];
> -      uint32_t result = (is_type(((word >> 0) & 0xFF), bitmask) & is_type(((word >> 8) & 0xFF), bitmask) &
> -                         is_type(((word >> 16) & 0xFF), bitmask) & is_type(((word >> 24) & 0xFF), bitmask));
> -      if (result == 0) {
> -        unsigned char *cptr = (unsigned char *)&(wptr[i]);
> -        if (!is_type(cptr[0], bitmask))
> -          return (&cptr[0]);
> -        if (!is_type(cptr[1], bitmask))
> -          return (&cptr[1]);
> -        if (!is_type(cptr[2], bitmask))
> -          return (&cptr[2]);
> -        return (&cptr[3]);
> -      }
> -    }
> -
> -    align_ptr = (unsigned char *)&(wptr[words]);
> -
> -    switch (b_bytes) {
> -    case 1:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      break;
> -    case 2:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&align_ptr[1]);
> -      break;
> -    case 3:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&align_ptr[1]);
> -      if (!is_type(align_ptr[2], bitmask))
> -        return (&align_ptr[2]);
> -      break;
> -    default:
> -      break;
> -    }
> -  }
> -  return 0;
> -}
> -
> -
> void
> ParseRules::ink_tolower_buffer(char *ptr, unsigned int n)
> {
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.h
> ----------------------------------------------------------------------
> diff --git a/lib/ts/ParseRules.h b/lib/ts/ParseRules.h
> index 4045b6d..ae248de 100644
> --- a/lib/ts/ParseRules.h
> +++ b/lib/ts/ParseRules.h
> @@ -162,8 +162,6 @@ public:
>   static const char *memchr(const char *s, char c, int max_length);
>   static const char *strchr(const char *s, char c);
> 
> -  static unsigned char *scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask);
> -
> private:
>   ParseRules(const ParseRules &);
>   ParseRules &operator=(const ParseRules &);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/Alarms.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/Alarms.cc b/mgmt/Alarms.cc
> index 7bfee8a..3511b70 100644
> --- a/mgmt/Alarms.cc
> +++ b/mgmt/Alarms.cc
> @@ -413,6 +413,7 @@ Alarms::constructAlarmMessage(const AppVersionInfo &version, char *ip, char *mes
>       if (max >= 1) {
>         message[0] = '\0';
>       }
> +      ink_mutex_release(&mutex);
>       return;
>     }
>     ink_strlcpy(&message[n], "alarm: none\n", max - n);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/LocalManager.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
> index 30f8cac..9d41a8a 100644
> --- a/mgmt/LocalManager.cc
> +++ b/mgmt/LocalManager.cc
> @@ -601,7 +601,7 @@ LocalManager::handleMgmtMsgFromProcesses(MgmtMessageHdr *mh)
>                 data_raw);
>       break;
>     }
> -  }
> +  } break;
>   case MGMT_SIGNAL_LOG_FILES_ROLLED: {
>     Debug("lm", "Rolling logs %s", (char *)data_raw);
>     break;
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/MultiFile.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/MultiFile.cc b/mgmt/MultiFile.cc
> index 9bd04d3..a0c8773 100644
> --- a/mgmt/MultiFile.cc
> +++ b/mgmt/MultiFile.cc
> @@ -125,6 +125,7 @@ MultiFile::WalkFiles(ExpandingArray *fileList)
>     } else {
>       if (stat(records_config_filePath, &records_config_fileInfo) < 0) {
>         delete[] filePath;
> +        delete[] records_config_filePath;
>         continue;
>       }
>       // Ignore ., .., and any dot files
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/api/EventCallback.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/api/EventCallback.cc b/mgmt/api/EventCallback.cc
> index f9736d8..c86ad3f 100644
> --- a/mgmt/api/EventCallback.cc
> +++ b/mgmt/api/EventCallback.cc
> @@ -213,18 +213,20 @@ cb_table_register(CallbackTable *cb_table, const char *event_name, TSEventSignal
>   } else { // register callback for specific alarm
>     // printf("[EventSignalCbRegister] Register callback for %s\n", event_name);
>     id = get_event_id(event_name);
> -    if (!cb_table->event_callback_l[id]) {
> -      cb_table->event_callback_l[id] = create_queue();
> -      first_time = 1;
> -    }
> +    if (id != -1) {
> +      if (!cb_table->event_callback_l[id]) {
> +        cb_table->event_callback_l[id] = create_queue();
> +        first_time = 1;
> +      }
> 
> -    if (!cb_table->event_callback_l[id]) {
> -      ink_mutex_release(&cb_table->event_callback_lock);
> -      return TS_ERR_SYS_CALL;
> +      if (!cb_table->event_callback_l[id]) {
> +        ink_mutex_release(&cb_table->event_callback_lock);
> +        return TS_ERR_SYS_CALL;
> +      }
> +      // now add to list
> +      event_cb = create_event_callback(func, data);
> +      enqueue(cb_table->event_callback_l[id], event_cb);
>     }
> -    // now add to list
> -    event_cb = create_event_callback(func, data);
> -    enqueue(cb_table->event_callback_l[id], event_cb);
>   }
> 
>   // release lock on callback table
> @@ -301,41 +303,43 @@ cb_table_unregister(CallbackTable *cb_table, const char *event_name, TSEventSign
>   } else {
>     // unregister for specific event
>     int id = get_event_id(event_name);
> -    if (cb_table->event_callback_l[id]) {
> -      int queue_depth;
> -
> -      queue_depth = queue_len(cb_table->event_callback_l[id]);
> -      // func == NULL means unregister all functions associated with alarm
> -      if (func == NULL) {
> -        while (!queue_is_empty(cb_table->event_callback_l[id])) {
> -          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> -          delete_event_callback(event_cb);
> -        }
> -
> -        // clean up queue and set to NULL
> -        delete_queue(cb_table->event_callback_l[id]);
> -        cb_table->event_callback_l[id] = NULL;
> -      } else {
> -        // remove this function
> -        for (int j = 0; j < queue_depth; j++) {
> -          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> -          cb_fun = event_cb->func;
> +    if (id != -1) {
> +      if (cb_table->event_callback_l[id]) {
> +        int queue_depth;
> 
> -          // the pointers are the same
> -          if (*cb_fun == *func) {
> +        queue_depth = queue_len(cb_table->event_callback_l[id]);
> +        // func == NULL means unregister all functions associated with alarm
> +        if (func == NULL) {
> +          while (!queue_is_empty(cb_table->event_callback_l[id])) {
> +            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
>             delete_event_callback(event_cb);
> -            continue;
>           }
> 
> -          enqueue(cb_table->event_callback_l[id], event_cb);
> -        }
> -
> -        // is queue empty now?
> -        if (queue_is_empty(cb_table->event_callback_l[id])) {
> +          // clean up queue and set to NULL
>           delete_queue(cb_table->event_callback_l[id]);
>           cb_table->event_callback_l[id] = NULL;
> -        }
> -      } // end if NULL else
> +        } else {
> +          // remove this function
> +          for (int j = 0; j < queue_depth; j++) {
> +            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> +            cb_fun = event_cb->func;
> +
> +            // the pointers are the same
> +            if (*cb_fun == *func) {
> +              delete_event_callback(event_cb);
> +              continue;
> +            }
> +
> +            enqueue(cb_table->event_callback_l[id], event_cb);
> +          }
> +
> +          // is queue empty now?
> +          if (queue_is_empty(cb_table->event_callback_l[id])) {
> +            delete_queue(cb_table->event_callback_l[id]);
> +            cb_table->event_callback_l[id] = NULL;
> +          }
> +        } // end if NULL else
> +      }
>     }
>   }
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> ----------------------------------------------------------------------
> diff --git a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> index 5eab951..c130af4 100644
> --- a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> +++ b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> @@ -268,6 +268,7 @@ consume_resource(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED)
>   case TS_EVENT_VCONN_WRITE_READY:
>     // We shouldn't get here because we specify the exact size of the buffer.
>     TSDebug(PLUGIN_NAME, "Write Ready");
> +    break;
>   case TS_EVENT_VCONN_WRITE_COMPLETE:
>     TSDebug(PLUGIN_NAME, "Write Complete");
>     // TSDebug(PLUGIN_NAME, "TSVConnShutdown()");
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/InkAPI.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
> index 6c4129e..f634d52 100644
> --- a/proxy/InkAPI.cc
> +++ b/proxy/InkAPI.cc
> @@ -4007,7 +4007,7 @@ TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->request_get();
>   *obj = reinterpret_cast<TSMLoc>(info->request_get()->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> }
> 
> 
> @@ -4018,7 +4018,7 @@ TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->response_get();
>   *obj = reinterpret_cast<TSMLoc>(info->response_get()->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> }
> 
> time_t
> @@ -4592,7 +4592,7 @@ TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4613,7 +4613,7 @@ TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4633,7 +4633,7 @@ TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4673,7 +4673,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
>   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -4711,7 +4711,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
>   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -4745,7 +4745,7 @@ TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   ink_assert(c_resp != NULL && c_resp->valid());
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = c_resp;
>   *obj = reinterpret_cast<TSMLoc>(c_resp->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -8671,13 +8671,13 @@ TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response)
>   // We allow for either request or response to be empty (or both), in
>   // which case we default to the transactions request or response.
>   if (request) {
> -    sdk_sanity_check_mbuffer(request);
> +    sdk_assert(sdk_sanity_check_mbuffer(request) == TS_SUCCESS);
>     req = reinterpret_cast<HTTPHdr *>(request);
>   } else {
>     req = &(sm->t_state.hdr_info.client_request);
>   }
>   if (response) {
> -    sdk_sanity_check_mbuffer(response);
> +    sdk_assert(sdk_sanity_check_mbuffer(response) == TS_SUCCESS);
>     resp = reinterpret_cast<HTTPHdr *>(response);
>   } else {
>     resp = &(sm->t_state.hdr_info.server_response);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/SocksProxy.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/SocksProxy.cc b/proxy/SocksProxy.cc
> index 9d8d48b..1ff2f78 100644
> --- a/proxy/SocksProxy.cc
> +++ b/proxy/SocksProxy.cc
> @@ -467,9 +467,9 @@ SocksProxy::setupHttpRequest(unsigned char *p)
>     // just use the last 4 octets as IPv4 addr:
>     a->type = SOCKS_ATYPE_IPV4;
>     a->addr.ipv4[0] = p[16];
> -    a->addr.ipv4[0] = p[17];
> -    a->addr.ipv4[0] = p[18];
> -    a->addr.ipv4[0] = p[19];
> +    a->addr.ipv4[1] = p[17];
> +    a->addr.ipv4[2] = p[18];
> +    a->addr.ipv4[3] = p[19];
> 
>     break;
>   default:
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/congest/CongestionTest.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/congest/CongestionTest.cc b/proxy/congest/CongestionTest.cc
> index 1e0dcb8..f546f54 100644
> --- a/proxy/congest/CongestionTest.cc
> +++ b/proxy/congest/CongestionTest.cc
> @@ -84,11 +84,13 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>     if (i % 2 == 1 && data == 0) {
>       rprintf(t, "verify content failed: key(%d) deleted\n", i);
>       *pstatus = REGRESSION_TEST_FAILED;
> +      delete htable;
>       return;
>     }
>     if (data != 0 && data != i) {
>       rprintf(t, "verify content failed: key(%d) data(%d)\n", i, data);
>       *pstatus = REGRESSION_TEST_FAILED;
> +      delete htable;
>       return;
>     }
>     if (i % (count / 50) == 0)
> @@ -128,6 +130,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>       if (data != htable->lookup_entry(data)) {
>         rprintf(t, "verify content failed: key(%d) data(%d)\n", data, htable->lookup_entry(data));
>         *pstatus = REGRESSION_TEST_FAILED;
> +        delete htable;
>         return;
>       }
>     }
> @@ -137,6 +140,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>   if (new_count != 0) {
>     rprintf(t, "there are %d extra entries in the table\n", new_count);
>     *pstatus = REGRESSION_TEST_FAILED;
> +    delete htable;
>     return;
>   }
> 
> @@ -157,6 +161,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>   if (new_count != 0) {
>     rprintf(t, "there are %d extra entries in the table\n", new_count);
>     *pstatus = REGRESSION_TEST_FAILED;
> +    delete htable;
>     return;
>   }
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http/HttpClientSession.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/http/HttpClientSession.cc b/proxy/http/HttpClientSession.cc
> index f02834c..0ba1e54 100644
> --- a/proxy/http/HttpClientSession.cc
> +++ b/proxy/http/HttpClientSession.cc
> @@ -313,7 +313,7 @@ HttpClientSession::do_io_close(int alerrno)
>     if (ssl_vc) {
>       ssl_vc->set_ssl_iobuf(NULL);
>     }
> -    if (upgrade_to_h2c) {
> +    if (upgrade_to_h2c && this->current_reader) {
>       Http2ClientSession *h2_session = http2ClientSessionAllocator.alloc();
> 
>       h2_session->set_upgrade_context(&current_reader->t_state.hdr_info.client_request);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http2/Http2ClientSession.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
> index 0ea6fca..386195b 100644
> --- a/proxy/http2/Http2ClientSession.cc
> +++ b/proxy/http2/Http2ClientSession.cc
> @@ -138,6 +138,7 @@ Http2ClientSession::set_upgrade_context(HTTPHdr *h)
>   upgrade_context.req_header->copy(h);
> 
>   MIMEField *settings = upgrade_context.req_header->field_find(MIME_FIELD_HTTP2_SETTINGS, MIME_LEN_HTTP2_SETTINGS);
> +  ink_release_assert(settings != NULL);
>   int svlen;
>   const char *sv = settings->value_get(&svlen);
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/logging/Log.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
> index 598ec6b..03ef392 100644
> --- a/proxy/logging/Log.cc
> +++ b/proxy/logging/Log.cc
> @@ -1432,6 +1432,7 @@ Log::match_logobject(LogBufferHeader *header)
>         obj = NULL;
>       }
>     }
> +    delete fmt;
>   }
>   return obj;
> }
> 


Re: trafficserver git commit: Coverity issues: making the sanity check calls useful!

Posted by James Peach <jp...@apache.org>.
This has multiple, independent changes, so it should have been a series of separate commits. I think it is also worth referencing the Coverity CID (I assume that this fixes a number of them?)


> On Aug 11, 2015, at 2:18 PM, amc@apache.org wrote:
> 
> Repository: trafficserver
> Updated Branches:
>  refs/heads/master f65b867bd -> 3d0d2564c
> 
> 
> Coverity issues: making the sanity check calls useful!
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/3d0d2564
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/3d0d2564
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/3d0d2564
> 
> Branch: refs/heads/master
> Commit: 3d0d2564cc91bcb32174f1b8a61d903a30eda8b5
> Parents: f65b867
> Author: Syeda Persia Aziz <pe...@yahoo.com>
> Authored: Mon Jul 20 18:16:17 2015 -0500
> Committer: Alan M. Carroll <am...@apache.org>
> Committed: Tue Aug 11 16:00:59 2015 -0500
> 
> ----------------------------------------------------------------------
> iocore/cache/RamCacheCLFUS.cc                   |  2 +
> lib/atscppapi/src/Plugin.cc                     |  3 +-
> lib/ts/ParseRules.cc                            | 83 --------------------
> lib/ts/ParseRules.h                             |  2 -
> mgmt/Alarms.cc                                  |  1 +
> mgmt/LocalManager.cc                            |  2 +-
> mgmt/MultiFile.cc                               |  1 +
> mgmt/api/EventCallback.cc                       | 82 ++++++++++---------
> .../stale_while_revalidate.c                    |  1 +
> proxy/InkAPI.cc                                 | 20 ++---
> proxy/SocksProxy.cc                             |  6 +-
> proxy/congest/CongestionTest.cc                 |  5 ++
> proxy/http/HttpClientSession.cc                 |  2 +-
> proxy/http2/Http2ClientSession.cc               |  1 +
> proxy/logging/Log.cc                            |  1 +
> 15 files changed, 72 insertions(+), 140 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/iocore/cache/RamCacheCLFUS.cc
> ----------------------------------------------------------------------
> diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
> index 0e051b2..8eb72ce 100644
> --- a/iocore/cache/RamCacheCLFUS.cc
> +++ b/iocore/cache/RamCacheCLFUS.cc
> @@ -310,6 +310,8 @@ RamCacheCLFUS::tick()
>     return;
>   e = lru[1].dequeue();
> Lfree:
> +  if (!e) // e may be NULL after e= lru[1].dequeue()
> +    return;
>   e->flag_bits.lru = 0;
>   history--;
>   uint32_t b = e->key.slice32(3) % nbuckets;
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/atscppapi/src/Plugin.cc
> ----------------------------------------------------------------------
> diff --git a/lib/atscppapi/src/Plugin.cc b/lib/atscppapi/src/Plugin.cc
> index 6de4391..176a030 100644
> --- a/lib/atscppapi/src/Plugin.cc
> +++ b/lib/atscppapi/src/Plugin.cc
> @@ -34,5 +34,6 @@ atscppapi::RegisterGlobalPlugin(std::string name, std::string vendor, std::strin
>   info.plugin_name = const_cast<char *>(name.c_str());
>   info.vendor_name = const_cast<char *>(vendor.c_str());
>   info.support_email = const_cast<char *>(email.c_str());
> -  TSPluginRegister(&info);
> +  if (TSPluginRegister(&info) != TS_SUCCESS)
> +    TSError("[Plugin.cc] Plugin registration failed.");
> }
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.cc
> ----------------------------------------------------------------------
> diff --git a/lib/ts/ParseRules.cc b/lib/ts/ParseRules.cc
> index ffc4a4e..6bd61b7 100644
> --- a/lib/ts/ParseRules.cc
> +++ b/lib/ts/ParseRules.cc
> @@ -41,89 +41,6 @@ const char parseRulesCTypeToLower[256] = {
> #include "ParseRulesCTypeToLower"
> };
> 
> -unsigned char *
> -ParseRules::scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask)
> -{
> -  unsigned int i;
> -  uint32_t *wptr;
> -  unsigned char *align_ptr;
> -  uintptr_t f_bytes, b_bytes, words, align_off;
> -
> -  align_off = ((uintptr_t)ptr & 3);
> -  align_ptr = (unsigned char *)(((uintptr_t)ptr) & ~3);
> -
> -  f_bytes = (align_off ? 4 - align_off : 0);
> -
> -  words = (n - f_bytes) >> 2;
> -
> -  if (words == 0) {
> -    for (i = 0; i < n; i++)
> -      if (!is_type(ptr[i], bitmask))
> -        return (&ptr[i]);
> -  } else {
> -    wptr = ((uint32_t *)align_ptr) + (align_off ? 1 : 0);
> -    switch (align_off) {
> -    case 1:
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&ptr[1]);
> -    case 2:
> -      if (!is_type(align_ptr[2], bitmask))
> -        return (&ptr[2]);
> -    case 3:
> -      if (!is_type(align_ptr[3], bitmask))
> -        return (&ptr[3]);
> -      break;
> -    default:
> -      break;
> -    }
> -
> -    b_bytes = n - ((words << 2) + f_bytes);
> -
> -    for (i = 0; i < words; i++) {
> -      uint32_t word = wptr[i];
> -      uint32_t result = (is_type(((word >> 0) & 0xFF), bitmask) & is_type(((word >> 8) & 0xFF), bitmask) &
> -                         is_type(((word >> 16) & 0xFF), bitmask) & is_type(((word >> 24) & 0xFF), bitmask));
> -      if (result == 0) {
> -        unsigned char *cptr = (unsigned char *)&(wptr[i]);
> -        if (!is_type(cptr[0], bitmask))
> -          return (&cptr[0]);
> -        if (!is_type(cptr[1], bitmask))
> -          return (&cptr[1]);
> -        if (!is_type(cptr[2], bitmask))
> -          return (&cptr[2]);
> -        return (&cptr[3]);
> -      }
> -    }
> -
> -    align_ptr = (unsigned char *)&(wptr[words]);
> -
> -    switch (b_bytes) {
> -    case 1:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      break;
> -    case 2:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&align_ptr[1]);
> -      break;
> -    case 3:
> -      if (!is_type(align_ptr[0], bitmask))
> -        return (&align_ptr[0]);
> -      if (!is_type(align_ptr[1], bitmask))
> -        return (&align_ptr[1]);
> -      if (!is_type(align_ptr[2], bitmask))
> -        return (&align_ptr[2]);
> -      break;
> -    default:
> -      break;
> -    }
> -  }
> -  return 0;
> -}
> -
> -
> void
> ParseRules::ink_tolower_buffer(char *ptr, unsigned int n)
> {
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/lib/ts/ParseRules.h
> ----------------------------------------------------------------------
> diff --git a/lib/ts/ParseRules.h b/lib/ts/ParseRules.h
> index 4045b6d..ae248de 100644
> --- a/lib/ts/ParseRules.h
> +++ b/lib/ts/ParseRules.h
> @@ -162,8 +162,6 @@ public:
>   static const char *memchr(const char *s, char c, int max_length);
>   static const char *strchr(const char *s, char c);
> 
> -  static unsigned char *scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask);
> -
> private:
>   ParseRules(const ParseRules &);
>   ParseRules &operator=(const ParseRules &);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/Alarms.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/Alarms.cc b/mgmt/Alarms.cc
> index 7bfee8a..3511b70 100644
> --- a/mgmt/Alarms.cc
> +++ b/mgmt/Alarms.cc
> @@ -413,6 +413,7 @@ Alarms::constructAlarmMessage(const AppVersionInfo &version, char *ip, char *mes
>       if (max >= 1) {
>         message[0] = '\0';
>       }
> +      ink_mutex_release(&mutex);
>       return;
>     }
>     ink_strlcpy(&message[n], "alarm: none\n", max - n);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/LocalManager.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/LocalManager.cc b/mgmt/LocalManager.cc
> index 30f8cac..9d41a8a 100644
> --- a/mgmt/LocalManager.cc
> +++ b/mgmt/LocalManager.cc
> @@ -601,7 +601,7 @@ LocalManager::handleMgmtMsgFromProcesses(MgmtMessageHdr *mh)
>                 data_raw);
>       break;
>     }
> -  }
> +  } break;
>   case MGMT_SIGNAL_LOG_FILES_ROLLED: {
>     Debug("lm", "Rolling logs %s", (char *)data_raw);
>     break;
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/MultiFile.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/MultiFile.cc b/mgmt/MultiFile.cc
> index 9bd04d3..a0c8773 100644
> --- a/mgmt/MultiFile.cc
> +++ b/mgmt/MultiFile.cc
> @@ -125,6 +125,7 @@ MultiFile::WalkFiles(ExpandingArray *fileList)
>     } else {
>       if (stat(records_config_filePath, &records_config_fileInfo) < 0) {
>         delete[] filePath;
> +        delete[] records_config_filePath;
>         continue;
>       }
>       // Ignore ., .., and any dot files
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/mgmt/api/EventCallback.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/api/EventCallback.cc b/mgmt/api/EventCallback.cc
> index f9736d8..c86ad3f 100644
> --- a/mgmt/api/EventCallback.cc
> +++ b/mgmt/api/EventCallback.cc
> @@ -213,18 +213,20 @@ cb_table_register(CallbackTable *cb_table, const char *event_name, TSEventSignal
>   } else { // register callback for specific alarm
>     // printf("[EventSignalCbRegister] Register callback for %s\n", event_name);
>     id = get_event_id(event_name);
> -    if (!cb_table->event_callback_l[id]) {
> -      cb_table->event_callback_l[id] = create_queue();
> -      first_time = 1;
> -    }
> +    if (id != -1) {
> +      if (!cb_table->event_callback_l[id]) {
> +        cb_table->event_callback_l[id] = create_queue();
> +        first_time = 1;
> +      }
> 
> -    if (!cb_table->event_callback_l[id]) {
> -      ink_mutex_release(&cb_table->event_callback_lock);
> -      return TS_ERR_SYS_CALL;
> +      if (!cb_table->event_callback_l[id]) {
> +        ink_mutex_release(&cb_table->event_callback_lock);
> +        return TS_ERR_SYS_CALL;
> +      }
> +      // now add to list
> +      event_cb = create_event_callback(func, data);
> +      enqueue(cb_table->event_callback_l[id], event_cb);
>     }
> -    // now add to list
> -    event_cb = create_event_callback(func, data);
> -    enqueue(cb_table->event_callback_l[id], event_cb);
>   }
> 
>   // release lock on callback table
> @@ -301,41 +303,43 @@ cb_table_unregister(CallbackTable *cb_table, const char *event_name, TSEventSign
>   } else {
>     // unregister for specific event
>     int id = get_event_id(event_name);
> -    if (cb_table->event_callback_l[id]) {
> -      int queue_depth;
> -
> -      queue_depth = queue_len(cb_table->event_callback_l[id]);
> -      // func == NULL means unregister all functions associated with alarm
> -      if (func == NULL) {
> -        while (!queue_is_empty(cb_table->event_callback_l[id])) {
> -          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> -          delete_event_callback(event_cb);
> -        }
> -
> -        // clean up queue and set to NULL
> -        delete_queue(cb_table->event_callback_l[id]);
> -        cb_table->event_callback_l[id] = NULL;
> -      } else {
> -        // remove this function
> -        for (int j = 0; j < queue_depth; j++) {
> -          event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> -          cb_fun = event_cb->func;
> +    if (id != -1) {
> +      if (cb_table->event_callback_l[id]) {
> +        int queue_depth;
> 
> -          // the pointers are the same
> -          if (*cb_fun == *func) {
> +        queue_depth = queue_len(cb_table->event_callback_l[id]);
> +        // func == NULL means unregister all functions associated with alarm
> +        if (func == NULL) {
> +          while (!queue_is_empty(cb_table->event_callback_l[id])) {
> +            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
>             delete_event_callback(event_cb);
> -            continue;
>           }
> 
> -          enqueue(cb_table->event_callback_l[id], event_cb);
> -        }
> -
> -        // is queue empty now?
> -        if (queue_is_empty(cb_table->event_callback_l[id])) {
> +          // clean up queue and set to NULL
>           delete_queue(cb_table->event_callback_l[id]);
>           cb_table->event_callback_l[id] = NULL;
> -        }
> -      } // end if NULL else
> +        } else {
> +          // remove this function
> +          for (int j = 0; j < queue_depth; j++) {
> +            event_cb = (EventCallbackT *)dequeue(cb_table->event_callback_l[id]);
> +            cb_fun = event_cb->func;
> +
> +            // the pointers are the same
> +            if (*cb_fun == *func) {
> +              delete_event_callback(event_cb);
> +              continue;
> +            }
> +
> +            enqueue(cb_table->event_callback_l[id], event_cb);
> +          }
> +
> +          // is queue empty now?
> +          if (queue_is_empty(cb_table->event_callback_l[id])) {
> +            delete_queue(cb_table->event_callback_l[id]);
> +            cb_table->event_callback_l[id] = NULL;
> +          }
> +        } // end if NULL else
> +      }
>     }
>   }
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> ----------------------------------------------------------------------
> diff --git a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> index 5eab951..c130af4 100644
> --- a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> +++ b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
> @@ -268,6 +268,7 @@ consume_resource(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED)
>   case TS_EVENT_VCONN_WRITE_READY:
>     // We shouldn't get here because we specify the exact size of the buffer.
>     TSDebug(PLUGIN_NAME, "Write Ready");
> +    break;
>   case TS_EVENT_VCONN_WRITE_COMPLETE:
>     TSDebug(PLUGIN_NAME, "Write Complete");
>     // TSDebug(PLUGIN_NAME, "TSVConnShutdown()");
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/InkAPI.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
> index 6c4129e..f634d52 100644
> --- a/proxy/InkAPI.cc
> +++ b/proxy/InkAPI.cc
> @@ -4007,7 +4007,7 @@ TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->request_get();
>   *obj = reinterpret_cast<TSMLoc>(info->request_get()->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> }
> 
> 
> @@ -4018,7 +4018,7 @@ TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = info->response_get();
>   *obj = reinterpret_cast<TSMLoc>(info->response_get()->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> }
> 
> time_t
> @@ -4592,7 +4592,7 @@ TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4613,7 +4613,7 @@ TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4633,7 +4633,7 @@ TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   if (hptr->valid()) {
>     *(reinterpret_cast<HTTPHdr **>(bufp)) = hptr;
>     *obj = reinterpret_cast<TSMLoc>(hptr->m_http);
> -    sdk_sanity_check_mbuffer(*bufp);
> +    sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
>     return TS_SUCCESS;
>   }
> 
> @@ -4673,7 +4673,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
>   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -4711,7 +4711,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
> 
>   *(reinterpret_cast<HdrHeapSDKHandle **>(bufp)) = *handle;
>   *obj = reinterpret_cast<TSMLoc>(cached_hdr->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -4745,7 +4745,7 @@ TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj)
>   ink_assert(c_resp != NULL && c_resp->valid());
>   *(reinterpret_cast<HTTPHdr **>(bufp)) = c_resp;
>   *obj = reinterpret_cast<TSMLoc>(c_resp->m_http);
> -  sdk_sanity_check_mbuffer(*bufp);
> +  sdk_assert(sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS);
> 
>   return TS_SUCCESS;
> }
> @@ -8671,13 +8671,13 @@ TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response)
>   // We allow for either request or response to be empty (or both), in
>   // which case we default to the transactions request or response.
>   if (request) {
> -    sdk_sanity_check_mbuffer(request);
> +    sdk_assert(sdk_sanity_check_mbuffer(request) == TS_SUCCESS);
>     req = reinterpret_cast<HTTPHdr *>(request);
>   } else {
>     req = &(sm->t_state.hdr_info.client_request);
>   }
>   if (response) {
> -    sdk_sanity_check_mbuffer(response);
> +    sdk_assert(sdk_sanity_check_mbuffer(response) == TS_SUCCESS);
>     resp = reinterpret_cast<HTTPHdr *>(response);
>   } else {
>     resp = &(sm->t_state.hdr_info.server_response);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/SocksProxy.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/SocksProxy.cc b/proxy/SocksProxy.cc
> index 9d8d48b..1ff2f78 100644
> --- a/proxy/SocksProxy.cc
> +++ b/proxy/SocksProxy.cc
> @@ -467,9 +467,9 @@ SocksProxy::setupHttpRequest(unsigned char *p)
>     // just use the last 4 octets as IPv4 addr:
>     a->type = SOCKS_ATYPE_IPV4;
>     a->addr.ipv4[0] = p[16];
> -    a->addr.ipv4[0] = p[17];
> -    a->addr.ipv4[0] = p[18];
> -    a->addr.ipv4[0] = p[19];
> +    a->addr.ipv4[1] = p[17];
> +    a->addr.ipv4[2] = p[18];
> +    a->addr.ipv4[3] = p[19];
> 
>     break;
>   default:
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/congest/CongestionTest.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/congest/CongestionTest.cc b/proxy/congest/CongestionTest.cc
> index 1e0dcb8..f546f54 100644
> --- a/proxy/congest/CongestionTest.cc
> +++ b/proxy/congest/CongestionTest.cc
> @@ -84,11 +84,13 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>     if (i % 2 == 1 && data == 0) {
>       rprintf(t, "verify content failed: key(%d) deleted\n", i);
>       *pstatus = REGRESSION_TEST_FAILED;
> +      delete htable;
>       return;
>     }
>     if (data != 0 && data != i) {
>       rprintf(t, "verify content failed: key(%d) data(%d)\n", i, data);
>       *pstatus = REGRESSION_TEST_FAILED;
> +      delete htable;
>       return;
>     }
>     if (i % (count / 50) == 0)
> @@ -128,6 +130,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>       if (data != htable->lookup_entry(data)) {
>         rprintf(t, "verify content failed: key(%d) data(%d)\n", data, htable->lookup_entry(data));
>         *pstatus = REGRESSION_TEST_FAILED;
> +        delete htable;
>         return;
>       }
>     }
> @@ -137,6 +140,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>   if (new_count != 0) {
>     rprintf(t, "there are %d extra entries in the table\n", new_count);
>     *pstatus = REGRESSION_TEST_FAILED;
> +    delete htable;
>     return;
>   }
> 
> @@ -157,6 +161,7 @@ EXCLUSIVE_REGRESSION_TEST(Congestion_HashTable)(RegressionTest *t, int /* atype
>   if (new_count != 0) {
>     rprintf(t, "there are %d extra entries in the table\n", new_count);
>     *pstatus = REGRESSION_TEST_FAILED;
> +    delete htable;
>     return;
>   }
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http/HttpClientSession.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/http/HttpClientSession.cc b/proxy/http/HttpClientSession.cc
> index f02834c..0ba1e54 100644
> --- a/proxy/http/HttpClientSession.cc
> +++ b/proxy/http/HttpClientSession.cc
> @@ -313,7 +313,7 @@ HttpClientSession::do_io_close(int alerrno)
>     if (ssl_vc) {
>       ssl_vc->set_ssl_iobuf(NULL);
>     }
> -    if (upgrade_to_h2c) {
> +    if (upgrade_to_h2c && this->current_reader) {
>       Http2ClientSession *h2_session = http2ClientSessionAllocator.alloc();
> 
>       h2_session->set_upgrade_context(&current_reader->t_state.hdr_info.client_request);
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/http2/Http2ClientSession.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/http2/Http2ClientSession.cc b/proxy/http2/Http2ClientSession.cc
> index 0ea6fca..386195b 100644
> --- a/proxy/http2/Http2ClientSession.cc
> +++ b/proxy/http2/Http2ClientSession.cc
> @@ -138,6 +138,7 @@ Http2ClientSession::set_upgrade_context(HTTPHdr *h)
>   upgrade_context.req_header->copy(h);
> 
>   MIMEField *settings = upgrade_context.req_header->field_find(MIME_FIELD_HTTP2_SETTINGS, MIME_LEN_HTTP2_SETTINGS);
> +  ink_release_assert(settings != NULL);
>   int svlen;
>   const char *sv = settings->value_get(&svlen);
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3d0d2564/proxy/logging/Log.cc
> ----------------------------------------------------------------------
> diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
> index 598ec6b..03ef392 100644
> --- a/proxy/logging/Log.cc
> +++ b/proxy/logging/Log.cc
> @@ -1432,6 +1432,7 @@ Log::match_logobject(LogBufferHeader *header)
>         obj = NULL;
>       }
>     }
> +    delete fmt;
>   }
>   return obj;
> }
>