Correct memory leak in listener test programme 64/6064/1
authorE. Scott Daniels <daniels@att.com>
Tue, 11 May 2021 15:46:24 +0000 (11:46 -0400)
committerE. Scott Daniels <daniels@att.com>
Tue, 11 May 2021 15:46:24 +0000 (11:46 -0400)
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 <daniels@att.com>
Change-Id: I4bbd24ccc044f4bc5e9e72051bb1f07e3d310d94

sidecars/listener/src/pipe_reader.c

index 88ad08f..501c6c5 100644 (file)
@@ -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 {