]> sigrok.org Git - libserialport.git/commitdiff
add_handle(): Fix a realloc() related issue.
authorUwe Hermann <redacted>
Fri, 3 Apr 2015 20:02:00 +0000 (22:02 +0200)
committerUwe Hermann <redacted>
Fri, 3 Apr 2015 20:02:42 +0000 (22:02 +0200)
serialport.c

index 1ace0ae32f9a5e97038573770ee8be30dc10f094..5183a85068d431996f970d9f714540b7c0ee9288 100644 (file)
@@ -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");
 
+       event_set->handles = new_handles;
+
        if (!(new_masks = realloc(event_set->masks,
-                       sizeof(enum sp_event) * (event_set->count + 1)))) {
-               free(new_handles);
+                       sizeof(enum sp_event) * (event_set->count + 1))))
                RETURN_ERROR(SP_ERR_MEM, "Mask array realloc() failed");
-       }
 
-       event_set->handles = new_handles;
        event_set->masks = new_masks;
 
        ((event_handle *) event_set->handles)[event_set->count] = handle;