From 59131d602894f5e2f8776fa9f4736d360f67579f Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 23 Nov 2013 20:55:18 +0000 Subject: [PATCH] Initialise structure in sp_new_config(). --- serialport.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/serialport.c b/serialport.c index f426fca..3f9989d 100644 --- a/serialport.c +++ b/serialport.c @@ -1467,13 +1467,27 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, enum sp_return sp_new_config(struct sp_port_config **config_ptr) { TRACE("%p", config_ptr); + struct sp_port_config *config; if (!config_ptr) RETURN_ERROR(SP_ERR_ARG, "Null result pointer"); - if (!(*config_ptr = malloc(sizeof(struct sp_port_config)))) + *config_ptr = NULL; + + if (!(config = malloc(sizeof(struct sp_port_config)))) RETURN_ERROR(SP_ERR_MEM, "config malloc failed"); + config->baudrate = -1; + config->bits = -1; + config->parity = -1; + config->stopbits = -1; + config->rts = -1; + config->cts = -1; + config->dtr = -1; + config->dsr = -1; + + *config_ptr = config; + RETURN_OK(); }