diff --git a/jtag/ChangeLog b/jtag/ChangeLog index f11ee3f2..4d8ddc36 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,11 @@ +2008-05-29 Kolja Waschk + + * src/tap/cable/wiggler.c src/tap/cable/generic_usbconn.c, + src/tap/cable/usbblaster.c, src/tap/cable/vision_ep9307.c, + src/tap/cable/jim.c, src/tap/cable/ft2232.c, + src/tap/cable/generic_parport.c: More malloc/free cleanup + in cable drivers (Hartley Sweeten) + 2008-05-28 Kolja Waschk * src/cmd/cable.c, src/tap/cable/wiggler.c, diff --git a/jtag/src/tap/cable/ft2232.c b/jtag/src/tap/cable/ft2232.c index bb554ec7..d72a731c 100644 --- a/jtag/src/tap/cable/ft2232.c +++ b/jtag/src/tap/cable/ft2232.c @@ -1279,17 +1279,22 @@ ft2232_connect( char *params[], cable_t *cable ) params_t *cable_params; int result; + /* perform generic_usbconn_connect */ + if ( ( result = generic_usbconn_connect( params, cable ) ) != 0 ) + return result; + cable_params = (params_t *)malloc( sizeof(params_t) ); if (!cable_params) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + /* NOTE: + * Call the underlying usbport driver (*free) routine directly + * not generic_usbconn_free() since it also free's cable->params + * (which is not established) and cable (which the caller will do) + */ + cable->link.usb->driver->free( cable->link.usb ); return 4; } - /* perform generic_usbconn_connect */ - result = generic_usbconn_connect( params, cable ); - - if (result == 0) - { cable_params->mpsse_frequency = 0; cable_params->last_tdo_valid = 0; @@ -1298,9 +1303,8 @@ ft2232_connect( char *params[], cable_t *cable ) /* exchange generic cable parameters with our private parameter set */ free( cable->params ); cable->params = cable_params; - } - return result; + return 0; } diff --git a/jtag/src/tap/cable/generic_parport.c b/jtag/src/tap/cable/generic_parport.c index a4027394..45e3d6c9 100644 --- a/jtag/src/tap/cable/generic_parport.c +++ b/jtag/src/tap/cable/generic_parport.c @@ -80,6 +80,7 @@ generic_parport_connect( char *params[], cable_t *cable ) cable_params = malloc( sizeof *cable_params ); if (!cable_params) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + parport_drivers[i]->parport_free( port ); return 4; } diff --git a/jtag/src/tap/cable/generic_usbconn.c b/jtag/src/tap/cable/generic_usbconn.c index 7e75ed7d..a9204f0b 100644 --- a/jtag/src/tap/cable/generic_usbconn.c +++ b/jtag/src/tap/cable/generic_usbconn.c @@ -145,12 +145,6 @@ generic_usbconn_connect( char *params[], cable_t *cable ) usbconn_t *conn = NULL; int i; - cable_params = malloc( sizeof(generic_params_t) ); - if (!cable_params) { - printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); - return 4; - } - if(strcasecmp(params[0], "usb") != 0) { user_specified.name = params[0]; @@ -212,6 +206,13 @@ generic_usbconn_connect( char *params[], cable_t *cable ) return 2; } + cable_params = malloc( sizeof(generic_params_t) ); + if (!cable_params) { + printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + usbconn_drivers[i]->free( conn ); + return 4; + } + cable->link.usb = conn; cable->params = cable_params; cable->chain = NULL; diff --git a/jtag/src/tap/cable/jim.c b/jtag/src/tap/cable/jim.c index 899887e5..da0e2f22 100644 --- a/jtag/src/tap/cable/jim.c +++ b/jtag/src/tap/cable/jim.c @@ -57,17 +57,18 @@ jim_cable_connect( char *params[], cable_t *cable ) printf( _("JTAG target simulator JIM - work in progress!\n")); - s = jim_init(); + s = jim_init(); if (!s) { printf( _("Initialization failed.\n") ); return 3; - } + } cable_params = malloc( sizeof(jim_cable_params_t) ); if (!cable_params) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + jim_free( s ); return 4; - } + } cable->params = cable_params; ((jim_cable_params_t *)(cable->params))->s = s; diff --git a/jtag/src/tap/cable/usbblaster.c b/jtag/src/tap/cable/usbblaster.c index 03006acf..e8862779 100644 --- a/jtag/src/tap/cable/usbblaster.c +++ b/jtag/src/tap/cable/usbblaster.c @@ -75,6 +75,12 @@ usbblaster_connect( char *params[], cable_t *cable ) if (!cable_params) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + /* NOTE: + * Call the underlying usbport driver (*free) routine directly + * not generic_usbconn_free() since it also free's cable->params + * (which is not established) and cable (which the caller will do) + */ + cable->link.usb->driver->free( cable->link.usb ); return 4; } diff --git a/jtag/src/tap/cable/vision_ep9307.c b/jtag/src/tap/cable/vision_ep9307.c index 43282f77..d28800f2 100644 --- a/jtag/src/tap/cable/vision_ep9307.c +++ b/jtag/src/tap/cable/vision_ep9307.c @@ -192,11 +192,6 @@ ep9307_connect( char *params[], cable_t *cable ) return 1; } - if (cable->params != NULL) { - printf( _("Disconnecting %s\n"), _(cable->driver->description) ); - cable->driver->disconnect( cable ); - } - printf( _("Initializing Vision EP9307 SoM GPIO JTAG Cable\n") ); cable_params = malloc( sizeof *cable_params ); diff --git a/jtag/src/tap/cable/wiggler.c b/jtag/src/tap/cable/wiggler.c index f71c953e..e49f76c0 100644 --- a/jtag/src/tap/cable/wiggler.c +++ b/jtag/src/tap/cable/wiggler.c @@ -191,6 +191,12 @@ wiggler_connect( char *params[], cable_t *cable ) wiggler_params = malloc( sizeof *wiggler_params ); if (!wiggler_params) { printf( _("%s(%d) malloc failed!\n"), __FILE__, __LINE__); + /* NOTE: + * Call the underlying parport driver (*free) routine directly + * not generic_parconn_free() since it also free's cable->params + * (which is not established) and cable (which the caller will do) + */ + cable->link.port->driver->parport_free( cable->link.port ); return 4; } @@ -198,13 +204,18 @@ wiggler_connect( char *params[], cable_t *cable ) free(cable->params); cable->params = wiggler_params; - if ( ! param_bitmap ) param_bitmap = (char *)std_wgl_map; if ( ( result = set_mapping( param_bitmap, cable ) ) != 0 ) { printf( _("Pin mapping failed\n") ); - free(cable->params); + /* NOTE: + * Call the underlying parport driver (*free) routine directly + * not generic_parconn_free() since it also free'scable (which + * the caller will do) + */ + cable->link.port->driver->parport_free( cable->link.port ); + free( cable->params ); return result; }