changeset 171:00afdf817f77

Bug 3223: Cannot set empty value to signal setting Reviewed-by: ykubota https://github.com/HeapStats/heapstats/pull/47
author Yasumasa Suenaga <yasuenag@gmail.com>
date Tue, 08 Nov 2016 22:34:43 +0900
parents 387a6530ff43
children 5dbec349fffe
files ChangeLog agent/src/heapstats-engines/configuration.cpp
diffstat 2 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 01 09:46:46 2016 +0900
+++ b/ChangeLog	Tue Nov 08 22:34:43 2016 +0900
@@ -1,3 +1,7 @@
+2016-11-08  Yasumasa Suenaga <yasuenag@gmail.com>
+
+	* Bug 3223: Cannot set empty value to signal setting
+
 2016-10-31  KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp>
 
 	* Bug 3214: heapstats-cli should check JAVA_HOME value
--- a/agent/src/heapstats-engines/configuration.cpp	Tue Nov 01 09:46:46 2016 +0900
+++ b/agent/src/heapstats-engines/configuration.cpp	Tue Nov 08 22:34:43 2016 +0900
@@ -265,7 +265,11 @@
  * \param dest [in] [out] Destination of this configuration.
  */
 void TConfiguration::ReadSignalValue(const char *value, char **dest) {
-  if (value == NULL) {
+  if ((value == NULL) || (value[0] == '\0')) {
+    if (*dest != NULL) {
+      free(*dest);
+    }
+
     *dest = NULL;
   } else if (isSupportSignal(value)) {
     if (*dest != NULL) {
@@ -353,9 +357,9 @@
   }
 
 #if USE_PCRE
-  TPCRERegex confRegex("^\\s*(\\S+?)\\s*=\\s*(\\S+)\\s*$", 9);
+  TPCRERegex confRegex("^\\s*(\\S+?)\\s*=\\s*(\\S+)?\\s*$", 9);
 #else
-  TCPPRegex confRegex("^\\s*(\\S+?)\\s*=\\s*(\\S+)\\s*$");
+  TCPPRegex confRegex("^\\s*(\\S+?)\\s*=\\s*(\\S+)?\\s*$");
 #endif
 
   /* Get string line from configure file. */
@@ -382,7 +386,13 @@
     if (confRegex.find(lineBuff)) {
       /* Key and value variables. */
       char *key = confRegex.group(1);
-      char *value = confRegex.group(2);
+      char *value;
+      try {
+        value = confRegex.group(2);
+      } catch (const char *errStr) {
+        logger->printDebugMsg(errStr);
+        value = (char *)calloc(1, sizeof(char));
+      }
 
       /* Check key name. */
       try {