From d278440273490b4010ccfca85ee71997b93075cf Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Mon, 6 Jan 2003 12:51:02 +0000 Subject: [PATCH] 2003-01-06 Marcel Telka * src/discovery.c (discovery): Fixed memory leaks, added out of memory test, added test for invalid IR length. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@293 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 5 +++++ jtag/src/discovery.c | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index e464d3af..39b7bf0a 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,8 @@ +2003-01-06 Marcel Telka + + * src/discovery.c (discovery): Fixed memory leaks, added out of memory test, + added test for invalid IR length. + 2003-01-05 Marcel Telka * include/register.h (register_inc, register_dec, register_shift_right, diff --git a/jtag/src/discovery.c b/jtag/src/discovery.c index aeaa5022..77f28e87 100644 --- a/jtag/src/discovery.c +++ b/jtag/src/discovery.c @@ -149,13 +149,17 @@ discovery( const char *filename ) if (!register_compare( ones, id )) { printf( "bad JTAG connection (TDO is 1)\n" ); fprintf( f, "bad JTAG connection (TDO is 1)\n" ); - return; /* FIXME: memory leak */ + break; } printf( "ID[%d]: %s\n", i, register_get_string( id ) ); fprintf( f, "ID[%d]: %s\n", i, register_get_string( id ) ); } + register_free( id ); + register_free( zeros ); + register_free( ones ); + if (i == MAX_CHAIN_LENGTH) { printf( "Warning: Maximum internal JTAG chain length exceeded!\n" ); fprintf( f, "Warning: Maximum internal JTAG chain length exceeded!\n" ); @@ -176,9 +180,23 @@ discovery( const char *filename ) printf( "IR length is %d\n\n", irlen ); fprintf( f, "IR length is %d\n\n", irlen ); + if (irlen < 1) { + printf( "Error: Invalid IR length!\n" ); + fclose( f ); + return; + } + ir = register_fill( register_alloc( irlen ), 0 ); irz = register_duplicate( ir ); - /* TODO: test for out of memory */ + + if (!ir || !irz) { + register_free( ir ); + register_free( irz ); + fclose( f ); + printf( "Error: Out of memory!\n" ); + return; + } + for (;;) { int rs;