From: E. Scott Daniels Date: Tue, 11 May 2021 15:46:24 +0000 (-0400) Subject: Correct memory leak in listener test programme X-Git-Tag: 1.12.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=384bf83739d17c8b9a80c47a682a5a6292c0dab7;p=ric-app%2Fmc.git Correct memory leak in listener test programme This change corrects a potential memory leak that Sonar has identified. The bug is not significant, and this change should not cause a release of even a patch update. Issue-ID: RIC-786 Signed-off-by: E. Scott Daniels Change-Id: I4bbd24ccc044f4bc5e9e72051bb1f07e3d310d94 --- diff --git a/sidecars/listener/src/pipe_reader.c b/sidecars/listener/src/pipe_reader.c index 88ad08f..501c6c5 100644 --- a/sidecars/listener/src/pipe_reader.c +++ b/sidecars/listener/src/pipe_reader.c @@ -65,7 +65,7 @@ static void sigh( int sig ) { //------------------------------------------------------------------------------------------ int main( int argc, char** argv ) { void* ctx; // the mc listener library context - char* dname = "/tmp/mcl/fifos"; // default directory where we open fifos + char* dname = NULL; // directory where we open fifos int pidx = 1; // parameter index int error = 0; int len; @@ -79,6 +79,7 @@ int main( int argc, char** argv ) { int blabber = 0; int max = 0; // we'll force one reader down early to simulate MC going away + dname = strdup( "/tmp/mcl/fifos" ); // default to this so we can blindly free in 'd' to keep sonar happy signal( SIGINT, sigh ); signal( SIGTERM, sigh ); @@ -86,6 +87,9 @@ int main( int argc, char** argv ) { switch( argv[pidx][1] ) { case 'd': if( pidx+1 < argc ) { + if( dname != NULL ) { + free( dname ); // keep sonar happy even though this is a test programme where a leak is meaningless + } dname = strdup( argv[pidx+1] ); pidx++; } else {