avrdude: Fix serial port handle leak in many places
This commit is contained in:
parent
a61a72cc94
commit
b7941345d1
5 changed files with 38 additions and 12 deletions
|
@ -158,8 +158,10 @@ static int arduino_open(PROGRAMMER * pgm, char * port)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stk500_getsync(pgm) < 0)
|
if (stk500_getsync(pgm) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1527,8 +1527,10 @@ static int jtagmkII_open(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1579,8 +1581,10 @@ static int jtagmkII_open_dw(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_DEBUGWIRE) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_DEBUGWIRE) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1631,8 +1635,10 @@ static int jtagmkII_open_pdi(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_PDI) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_PDI) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1684,8 +1690,10 @@ static int jtagmkII_dragon_open(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1737,8 +1745,10 @@ static int jtagmkII_dragon_open_dw(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_DEBUGWIRE) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_DEBUGWIRE) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1790,8 +1800,10 @@ static int jtagmkII_dragon_open_pdi(PROGRAMMER * pgm, char * port)
|
||||||
*/
|
*/
|
||||||
jtagmkII_drain(pgm, 0);
|
jtagmkII_drain(pgm, 0);
|
||||||
|
|
||||||
if (jtagmkII_getsync(pgm, EMULATOR_MODE_PDI) < 0)
|
if (jtagmkII_getsync(pgm, EMULATOR_MODE_PDI) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3370,6 +3382,8 @@ static int jtagmkII_open32(PROGRAMMER * pgm, char * port)
|
||||||
status = jtagmkII_getsync(pgm, -1);
|
status = jtagmkII_getsync(pgm, -1);
|
||||||
if(status < 0) return -1;
|
if(status < 0) return -1;
|
||||||
|
|
||||||
|
// FIXME: Error handling is bad here: memory leak in resp (?) and port not closed
|
||||||
|
|
||||||
// AVR32 "special"
|
// AVR32 "special"
|
||||||
buf[0] = CMND_SET_PARAMETER;
|
buf[0] = CMND_SET_PARAMETER;
|
||||||
buf[1] = 0x2D;
|
buf[1] = 0x2D;
|
||||||
|
|
|
@ -669,11 +669,15 @@ static int stk500_open(PROGRAMMER * pgm, char * port)
|
||||||
|
|
||||||
// MIB510 init
|
// MIB510 init
|
||||||
if (strcmp(ldata(lfirst(pgm->id)), "mib510") == 0 &&
|
if (strcmp(ldata(lfirst(pgm->id)), "mib510") == 0 &&
|
||||||
mib510_isp(pgm, 1) != 0)
|
mib510_isp(pgm, 1) != 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (stk500_getsync(pgm) < 0)
|
if (stk500_getsync(pgm) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1695,8 +1695,10 @@ static int stk500v2_open(PROGRAMMER * pgm, char * port)
|
||||||
stk500v2_drain(pgm, 0);
|
stk500v2_drain(pgm, 0);
|
||||||
|
|
||||||
if (pgm->bitclock != 0.0) {
|
if (pgm->bitclock != 0.0) {
|
||||||
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
|
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1753,8 +1755,10 @@ static int stk600_open(PROGRAMMER * pgm, char * port)
|
||||||
stk500v2_drain(pgm, 0);
|
stk500v2_drain(pgm, 0);
|
||||||
|
|
||||||
if (pgm->bitclock != 0.0) {
|
if (pgm->bitclock != 0.0) {
|
||||||
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0)
|
if (pgm->set_sck_period(pgm, pgm->bitclock) != 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -192,8 +192,10 @@ static int wiring_open(PROGRAMMER * pgm, char * port)
|
||||||
/* drain any extraneous input */
|
/* drain any extraneous input */
|
||||||
stk500v2_drain(pgm, 0);
|
stk500v2_drain(pgm, 0);
|
||||||
|
|
||||||
if (stk500v2_getsync(pgm) < 0)
|
if (stk500v2_getsync(pgm) < 0) {
|
||||||
|
serial_close(&pgm->fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue