fix: mem leak,

This commit is contained in:
iceman1001 2019-02-22 15:21:20 +01:00
commit ef9d1fa378

View file

@ -123,6 +123,7 @@ serial_port uart_open(const char* pcPortName) {
printf("Error: Could not connect\n"); printf("Error: Could not connect\n");
freeaddrinfo(addr); freeaddrinfo(addr);
free(addrstr); free(addrstr);
free(sp);
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
@ -132,7 +133,11 @@ serial_port uart_open(const char* pcPortName) {
sp->fd = sfd; sp->fd = sfd;
int one = 1; int one = 1;
setsockopt(sp->fd, SOL_TCP, TCP_NODELAY, &one, sizeof(one)); int res = setsockopt(sp->fd, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
if ( res != 0) {
free(sp);
return INVALID_SERIAL_PORT;
}
return sp; return sp;
} }
@ -359,8 +364,11 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
# endif # endif
default: return false; default: return false;
}; };
struct termios ti; struct termios ti;
if (tcgetattr(spu->fd,&ti) == -1) return false; if (tcgetattr(spu->fd,&ti) == -1)
return false;
// Set port speed (Input and Output) // Set port speed (Input and Output)
cfsetispeed(&ti, stPortSpeed); cfsetispeed(&ti, stPortSpeed);
cfsetospeed(&ti, stPortSpeed); cfsetospeed(&ti, stPortSpeed);