Hello,

The tool cppcheck [1] detected a memory leak in src/ifd/ifd-cyberjack.c

Checking ./src/ifd/ifd-cyberjack.c...
[./src/ifd/ifd-cyberjack.c:390]: Memory leak: state
    Defines=''

The state variable is allocated but not freed in case of error.
I propose the attached patch. I am not sure it is correct. Please review.

Bye

[1] http://packages.debian.org/sid/cppcheck

-- 
 Dr. Ludovic Rousseau
Index: src/ifd/ifd-cyberjack.c
===================================================================
--- src/ifd/ifd-cyberjack.c     (révision 1081)
+++ src/ifd/ifd-cyberjack.c     (copie de travail)
@@ -387,29 +387,34 @@ static int cyberjack_activate(ifd_reader
            ifd_device_send( dev, (unsigned char*)"\x00\x04\x00" 
"\xe2\xc0\x00\x22", 7 ) != 7 )
        {
                cyberjack_ct_error(80, "cyberjack: failed to activate 1");
+               free(state);
                return -1;
        }
        
        ifd_msleep( 100 );
        if( (ret=cyberjack_recv_t1( state, 0xe2, read_buffer ))!=4 || memcmp( 
read_buffer, "\x2e\xe0\x00\xce", 4 )!=0 )  {
                cyberjack_ct_error(80, "cyberjack: failed to activate 2: no 
cookie");
+               free(state);
                return -1;
        }
 
        // send 20 11 00 00 
        if( cyberjack_send_t1( state, "\x12\x00\x04" "\x20\x11\x00\x00", 7 ) != 
7 )  {
                cyberjack_ct_error(80, "cyberjack: failed to activate 5");      
        
+               free(state);
                return -1;
        }
        ret = cyberjack_recv_t1( state, 0x12, read_buffer );
        if( ret < 0 )  {
                cyberjack_ct_error(80, "cyberjack: failed to activate 5.1");    
        
+               free(state);
                return -1;
        }
        cyberjack_ifd_debug(1, 80+ret*3, "cyberjack: t1 response is : %s", 
                        ct_hexdump( read_buffer, ret ));
        if( ret < 6 )  {
                cyberjack_ifd_debug(1, 80, "cyberjack: response is short 6.1");
+               free(state);
                return -1;
        }
        if( ret != 6 || read_buffer[3]!=0x90 || read_buffer[4]!=0 )
@@ -418,6 +423,7 @@ static int cyberjack_activate(ifd_reader
                        ct_hexdump( read_buffer, 6 ));
                // could neever recover from this
                cyberjack_ct_error(80, "cyberjack: failed to activate: failed 
to reset the reader");            
+               free(state);
                return -1;
        }
 
@@ -431,6 +437,7 @@ static int cyberjack_activate(ifd_reader
        ret = cyberjack_recv_t1( state, 0x2e, read_buffer );
        if( ret < 3 || memcmp(read_buffer, "\x2e\xe0\x00", 3 )!=0 )  {
                cyberjack_ct_error(80, "cyberjack: failed to activate 7.1");    
        
+               free(state);
                return -1;
        }
        
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to