]> sigrok.org Git - libserialport.git/commitdiff
add_handle(): Fix a memory leak.
authorUwe Hermann <redacted>
Fri, 3 Apr 2015 15:17:49 +0000 (17:17 +0200)
committerUwe Hermann <redacted>
Fri, 3 Apr 2015 15:51:41 +0000 (17:51 +0200)
This fixes the following scan-build warning:

  serialport.c:1170:3: warning: Potential leak of memory pointed to by 'new_handles'
                  RETURN_ERROR(SP_ERR_MEM, "Mask array realloc() failed");
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

serialport.c

index b8ddffe870e1e1fa4c2269471d78a6cbfb185195..1ace0ae32f9a5e97038573770ee8be30dc10f094 100644 (file)
@@ -1166,8 +1166,10 @@ static enum sp_return add_handle(struct sp_event_set *event_set,
                RETURN_ERROR(SP_ERR_MEM, "Handle array realloc() failed");
 
        if (!(new_masks = realloc(event_set->masks,
-                       sizeof(enum sp_event) * (event_set->count + 1))))
+                       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;
        event_set->masks = new_masks;