From ac323d80e0baaf6968c316dbcb2e5ffe4739cb2e Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Fri, 3 Apr 2015 22:02:00 +0200 Subject: [PATCH] add_handle(): Fix a realloc() related issue. --- serialport.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/serialport.c b/serialport.c index 1ace0ae..5183a85 100644 --- a/serialport.c +++ b/serialport.c @@ -1165,13 +1165,12 @@ static enum sp_return add_handle(struct sp_event_set *event_set, sizeof(event_handle) * (event_set->count + 1)))) RETURN_ERROR(SP_ERR_MEM, "Handle array realloc() failed"); - if (!(new_masks = realloc(event_set->masks, - sizeof(enum sp_event) * (event_set->count + 1)))) { - free(new_handles); - RETURN_ERROR(SP_ERR_MEM, "Mask array realloc() failed"); - } - event_set->handles = new_handles; + + if (!(new_masks = realloc(event_set->masks, + sizeof(enum sp_event) * (event_set->count + 1)))) + RETURN_ERROR(SP_ERR_MEM, "Mask array realloc() failed"); + event_set->masks = new_masks; ((event_handle *) event_set->handles)[event_set->count] = handle;