1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Fix memory leaks.

This commit is contained in:
Martin Ling 2013-11-22 18:43:41 +00:00 committed by Uwe Hermann
parent 7de20e3915
commit 8d43110ad7

View File

@ -610,11 +610,15 @@ static enum sp_return get_baudrate(int fd, int *baudrate)
if (!(data = malloc(get_termios_size()))) if (!(data = malloc(get_termios_size())))
return SP_ERR_MEM; return SP_ERR_MEM;
if (ioctl(fd, get_termios_get_ioctl(), data) < 0) if (ioctl(fd, get_termios_get_ioctl(), data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
*baudrate = get_termios_speed(data); *baudrate = get_termios_speed(data);
free(data);
return SP_OK; return SP_OK;
} }
@ -625,13 +629,19 @@ static enum sp_return set_baudrate(int fd, int baudrate)
if (!(data = malloc(get_termios_size()))) if (!(data = malloc(get_termios_size())))
return SP_ERR_MEM; return SP_ERR_MEM;
if (ioctl(fd, get_termios_get_ioctl(), data) < 0) if (ioctl(fd, get_termios_get_ioctl(), data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
set_termios_speed(data, baudrate); set_termios_speed(data, baudrate);
if (ioctl(fd, get_termios_set_ioctl(), data) < 0) if (ioctl(fd, get_termios_set_ioctl(), data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
free(data);
return SP_OK; return SP_OK;
} }
@ -644,11 +654,15 @@ static enum sp_return get_flow(int fd, int *flow)
if (!(data = malloc(get_termiox_size()))) if (!(data = malloc(get_termiox_size())))
return SP_ERR_MEM; return SP_ERR_MEM;
if (ioctl(fd, TCGETX, data) < 0) if (ioctl(fd, TCGETX, data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
*flow = get_termiox_flow(data); *flow = get_termiox_flow(data);
free(data);
return SP_OK; return SP_OK;
} }
@ -659,13 +673,19 @@ static enum sp_return set_flow(int fd, int flow)
if (!(data = malloc(get_termiox_size()))) if (!(data = malloc(get_termiox_size())))
return SP_ERR_MEM; return SP_ERR_MEM;
if (ioctl(fd, TCGETX, data) < 0) if (ioctl(fd, TCGETX, data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
set_termiox_flow(data, flow); set_termiox_flow(data, flow);
if (ioctl(fd, TCSETX, data) < 0) if (ioctl(fd, TCSETX, data) < 0) {
free(data);
return SP_ERR_FAIL; return SP_ERR_FAIL;
}
free(data);
return SP_OK; return SP_OK;
} }