浏览代码

HPCC-25475 Address Coverity scan results in Couchbase plugin

Signed-off-by: Dan S. Camper <dan.camper@lexisnexisrisk.com>
Dan S. Camper 4 年之前
父节点
当前提交
5a933b29d8
共有 2 个文件被更改,包括 22 次插入14 次删除
  1. 2 0
      plugins/couchbase/README.md
  2. 20 14
      plugins/couchbase/couchbaseembed.cpp

+ 2 - 0
plugins/couchbase/README.md

@@ -52,6 +52,8 @@ For example:
 
 ##N1QL Query Examples
 
+Note that only a single N1QL statement embedded function is supported at this time.
+
                 //Creates a primary index on 'mybucket' bucket
                 createprimeindex() := EMBED(couchbase : server(server), port(port), bucket('mybucket'))
                     CREATE PRIMARY INDEX ON iot;

+ 20 - 14
plugins/couchbase/couchbaseembed.cpp

@@ -181,6 +181,8 @@ namespace couchbaseembed
             auto status = pQcmd->named_param(cbPlaceholder.str(), utf8);
             if (!status.success())
                 failx("Could not bind Param: %s val: %s", cbPlaceholder.str(), utf8);
+            if (utf8)
+                rtlFree(utf8);
         }
         else
             failx("Internal error: detected invalid CouchbaseQueryCommand while attempting to bind to field: %s", cbPlaceholder.str());
@@ -215,6 +217,8 @@ namespace couchbaseembed
             auto status = pQcmd->named_param(cbPlaceholder.str(), (char *)data);
             if (!status.success())
                 failx("Could not bind Param: %s val: %s", cbPlaceholder.str(), (char *)data);
+            if (data)
+                rtlFree(data);
         }
         else
             failx("Internal error: detected invalid CouchbaseQueryCommand while attempting to bind to field: %s", cbPlaceholder.str());
@@ -912,32 +916,33 @@ namespace couchbaseembed
 
     IPropertyTree * CouchbaseEmbedFunctionContext::nextResultRowTree()
     {
-        for (auto cbrow : *m_pQuery)
+        if (m_pQuery)
         {
-            auto json = cbrow.json().to_string();
+            reportIfQueryFailure(m_pQuery);
+
+            // Only the first callback query is processed
+            auto json = m_pQuery->begin()->json().to_string();
             Owned<IPropertyTree> contentTree = createPTreeFromJSONString(json.c_str());
             return contentTree.getLink();
         }
 
-        reportIfQueryFailure(m_pQuery);
-
         return nullptr;
     }
 
     IPropertyTreeIterator * CouchbaseEmbedFunctionContext::nextResultRowIterator()
     {
-        for (auto cbrow : *m_pQuery)
+        if (m_pQuery)
         {
-            auto json = cbrow.json().to_string();
+            reportIfQueryFailure(m_pQuery);
+
+            // Only the first callback query is processed
+            auto json = m_pQuery->begin()->json().to_string();
             Owned<IPropertyTree> contentTree = createPTreeFromJSONString(json.c_str());
             if (contentTree)
                 return contentTree->getElements("./*");
             failx("Could not fetch next result row.");
-            break;
         }
 
-        reportIfQueryFailure(m_pQuery);
-
         return nullptr;
     }
 
@@ -1126,6 +1131,8 @@ namespace couchbaseembed
         auto status = m_pQcmd->named_param(cbPlaceholder.str(), (char *)data);
         if (!status.success())
             failx("Could not bind Param: %s val: %s", cbPlaceholder.str(), (char *)data);
+        if (data)
+            rtlFree(data);
     }
 
     void CouchbaseEmbedFunctionContext::bindFloatParam(const char *name, float val)
@@ -1198,6 +1205,8 @@ namespace couchbaseembed
         auto status = m_pQcmd->named_param(cbPlaceholder.str(), utf8);
         if (!status.success())
             failx("Could not bind Param: %s val: %s", cbPlaceholder.str(), utf8);
+        if (utf8)
+            rtlFree(utf8);
     }
 
     void CouchbaseEmbedFunctionContext::bindVStringParam(const char *name, const char *val)
@@ -1404,11 +1413,8 @@ namespace couchbaseembed
         size32_t chars;
         rtlDataAttr result;
         value.setString(strlen(dvalue), dvalue);
-        if (field)
-        {
-            RtlDecimalTypeInfo *dtype = (RtlDecimalTypeInfo *) field->type;
-            value.setPrecision(dtype->getDecimalDigits(), dtype->getDecimalPrecision());
-        }
+        RtlDecimalTypeInfo *dtype = (RtlDecimalTypeInfo *) field->type;
+        value.setPrecision(dtype->getDecimalDigits(), dtype->getDecimalPrecision());
     }
 
     void CouchbaseRowBuilder::processBeginSet(const RtlFieldInfo * field, bool &isAll)