From 6359b6a6e881a569c8588b6f2701a71e479fb5ae Mon Sep 17 00:00:00 2001 From: Nick Bofferding Date: Thu, 31 May 2018 15:12:26 -0500 Subject: Fix memory leaks associated with various msg_sendrecv calls Change-Id: I30bb6627610391aea248d4a3c4d722ef1695b02f Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/59677 Tested-by: Jenkins Server Tested-by: Jenkins OP Build CI Tested-by: Jenkins OP HW Reviewed-by: ILYA SMIRNOV Reviewed-by: Michael Baiocchi Reviewed-by: Nicholas E. Bofferding --- src/usr/console/console.C | 5 ++++- src/usr/errl/errlmanager.C | 6 +++++- src/usr/runtime/populate_hbruntime.C | 4 ++++ src/usr/trace/daemonif.C | 8 +++++++- 4 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/usr/console/console.C b/src/usr/console/console.C index 8a066fe85..eed9756cd 100644 --- a/src/usr/console/console.C +++ b/src/usr/console/console.C @@ -8,7 +8,6 @@ /* Contributors Listed Below - COPYRIGHT 2014 */ /* [+] Google Inc. */ /* [+] International Business Machines Corp. */ -/* [+] Google Inc. */ /* */ /* */ /* Licensed under the Apache License, Version 2.0 (the "License"); */ @@ -107,6 +106,10 @@ namespace CONSOLE msg_t* msg = msg_allocate(); msg->type = SYNC; msg_sendrecv(g_msgq, msg); + + // Always free since send/recv implies ownership + msg_free(msg); + msg=nullptr; } } diff --git a/src/usr/errl/errlmanager.C b/src/usr/errl/errlmanager.C index 24008e7ea..4476640f7 100644 --- a/src/usr/errl/errlmanager.C +++ b/src/usr/errl/errlmanager.C @@ -821,13 +821,17 @@ void ErrlManager::flushErrorLogs() TRACDCOMP( g_trac_errl, ENTER_MRK "ErrlManager::flushErrorLogs" ); // Create message to send to msg handler - msg_t *msg = NULL; + msg_t *msg = nullptr; msg = msg_allocate(); msg->type = ERRLOG_FLUSH_TYPE; do{ // Send message to msg handler, get msg back on l_RecvMsgQ int rc = msg_sendrecv(iv_msgQ,msg); + // Always free the message since send/recv implies ownership + msg_free(msg); + msg=nullptr; + if(rc) { TRACFCOMP(g_trac_errl, "Error sending error log flush message. " diff --git a/src/usr/runtime/populate_hbruntime.C b/src/usr/runtime/populate_hbruntime.C index 129068941..5e2c8ddb2 100644 --- a/src/usr/runtime/populate_hbruntime.C +++ b/src/usr/runtime/populate_hbruntime.C @@ -3286,6 +3286,10 @@ errlHndl_t persistent_rwAttrRuntimeCheck( void ) } } + // Always free the message since send/recv implies ownership + msg_free(l_msg); + l_msg=nullptr; + return l_err; } // end persistent_rwAttrRuntimeCheck diff --git a/src/usr/trace/daemonif.C b/src/usr/trace/daemonif.C index f84844800..90e3fbec0 100644 --- a/src/usr/trace/daemonif.C +++ b/src/usr/trace/daemonif.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2012,2016 */ +/* Contributors Listed Below - COPYRIGHT 2012,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -40,6 +40,7 @@ namespace TRACE msg->type = TRACE_DAEMON_SHUTDOWN; msg_sendrecv(iv_queue, msg); msg_free(msg); + msg=nullptr; } msg_q_destroy(iv_queue); @@ -58,6 +59,10 @@ namespace TRACE if (i_blocking) { msg_sendrecv(iv_queue, msg); // sync message due to 'blocking'. + + // Always free the message since send/receive implies ownership + msg_free(msg); + msg=nullptr; } else { @@ -76,6 +81,7 @@ namespace TRACE msg->data[0] = i_enable ? 0x2 : 0x0; msg_sendrecv(iv_queue, msg); msg_free(msg); + msg=nullptr; } } -- cgit v1.2.1