]> granicus.if.org Git - check/commitdiff
fix potential leaks when assigning result message
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 17 Dec 2013 22:12:20 +0000 (22:12 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Tue, 17 Dec 2013 22:12:20 +0000 (22:12 +0000)
In some cases, a result message has already been allocated,
which is then overwritten by set_fork_info(). Just in case,
check if tr->msg is not null, and if so free the value, before
assigning a new value.

git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@893 64e312b2-a51f-0410-8e61-82d0ca0eb02a

src/check_run.c

index a703d574f2cc660e20dfcfafe1bb7db97fc1fe9f..3b5d99ba7bcd89978a4d525d1342cd97683afb59 100644 (file)
@@ -470,27 +470,51 @@ static void set_fork_info (TestResult *tr, int status, int signal_expected, unsi
       if (alarm_received) {
         /* Got alarm instead of signal */
         tr->rtype = CK_ERROR;
+        if(tr->msg != NULL)
+        {
+          free(tr->msg);
+        }
         tr->msg = signal_error_msg(signal_received, signal_expected);
       } else {
         tr->rtype = CK_PASS;
+        if(tr->msg != NULL)
+        {
+          free(tr->msg);
+        }
         tr->msg = pass_msg();
       }
     } else if (signal_expected != 0) {
       /* signal received, but not the expected one */
       tr->rtype = CK_ERROR;
+      if(tr->msg != NULL)
+      {
+        free(tr->msg);
+      }
       tr->msg = signal_error_msg(signal_received, signal_expected);
     } else {
       /* signal received and none expected */
       tr->rtype = CK_ERROR;
+      if(tr->msg != NULL)
+      {
+        free(tr->msg);
+      }
       tr->msg = signal_msg(signal_received);
     }
   } else if (signal_expected == 0) {
     if (was_exit && exit_status == allowed_exit_value) {
       tr->rtype = CK_PASS;
+      if(tr->msg != NULL)
+      {
+        free(tr->msg);
+      }
       tr->msg = pass_msg();
     } else if (was_exit && exit_status != allowed_exit_value) {
       if (tr->msg == NULL) { /* early exit */
         tr->rtype = CK_ERROR;
+        if(tr->msg != NULL)
+        {
+          free(tr->msg);
+        }
         tr->msg = exit_msg(exit_status);
       } else {
         tr->rtype = CK_FAILURE;
@@ -498,6 +522,10 @@ static void set_fork_info (TestResult *tr, int status, int signal_expected, unsi
     }
   } else { /* a signal was expected and none raised */
     if (was_exit) {
+      if(tr->msg != NULL)
+      {
+        free(tr->msg);
+      }
       tr->msg = exit_msg(exit_status);
       if (exit_status == allowed_exit_value)
        tr->rtype = CK_FAILURE; /* normal exit status */