From 028d6764df2568217d87935c88dd1091fc887bee Mon Sep 17 00:00:00 2001 From: brarcher Date: Tue, 17 Dec 2013 22:12:20 +0000 Subject: [PATCH] fix potential leaks when assigning result message 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/check_run.c b/src/check_run.c index a703d57..3b5d99b 100644 --- a/src/check_run.c +++ b/src/check_run.c @@ -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 */ -- 2.40.0