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

Add sp_free_port() function.

This commit is contained in:
Martin Ling 2013-11-03 22:27:59 +00:00 committed by Uwe Hermann
parent 77f262c4f9
commit e3b2f7a4e3
2 changed files with 13 additions and 1 deletions

View File

@ -73,6 +73,17 @@ int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)
return SP_OK; 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) static struct sp_port **sp_list_append(struct sp_port **list, const char *portname)
{ {
void *tmp; void *tmp;
@ -313,7 +324,7 @@ void sp_free_port_list(struct sp_port **list)
{ {
unsigned int i; unsigned int i;
for (i = 0; list[i]; i++) for (i = 0; list[i]; i++)
free(list[i]); sp_free_port(list[i]);
free(list); free(list);
} }

View File

@ -80,6 +80,7 @@ enum {
}; };
int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr); 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); int sp_list_ports(struct sp_port ***list_ptr);
void sp_free_port_list(struct sp_port **ports); void sp_free_port_list(struct sp_port **ports);
int sp_open(struct sp_port *port, int flags); int sp_open(struct sp_port *port, int flags);