From e3b2f7a4e3c1315d51d6a91eec7dde44ec0a623b Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sun, 3 Nov 2013 22:27:59 +0000 Subject: [PATCH] Add sp_free_port() function. --- serialport.c | 13 ++++++++++++- serialport.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/serialport.c b/serialport.c index c2a1a0c..77d8b28 100644 --- a/serialport.c +++ b/serialport.c @@ -73,6 +73,17 @@ int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr) return SP_OK; } +void sp_free_port(struct sp_port *port) +{ + if (!port) + return; + + if (port->name) + free(port->name); + + free(port); +} + static struct sp_port **sp_list_append(struct sp_port **list, const char *portname) { void *tmp; @@ -313,7 +324,7 @@ void sp_free_port_list(struct sp_port **list) { unsigned int i; for (i = 0; list[i]; i++) - free(list[i]); + sp_free_port(list[i]); free(list); } diff --git a/serialport.h b/serialport.h index c7d4f7c..ac583e9 100644 --- a/serialport.h +++ b/serialport.h @@ -80,6 +80,7 @@ enum { }; int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); +void sp_free_port(struct sp_port *port); int sp_list_ports(struct sp_port ***list_ptr); void sp_free_port_list(struct sp_port **ports); int sp_open(struct sp_port *port, int flags);