Skip to content

Commit

Permalink
fix memory leak in rebind_symbols_image (#49)
Browse files Browse the repository at this point in the history
* fix memory leak in rebind_symbols_image
  • Loading branch information
rosen0510 authored and dinhvh committed Feb 2, 2018
1 parent 90e9f26 commit 06cfb58
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fishhook.c
Expand Up @@ -187,6 +187,9 @@ int rebind_symbols_image(void *header,
struct rebindings_entry *rebindings_head = NULL;
int retval = prepend_rebindings(&rebindings_head, rebindings, rebindings_nel);
rebind_symbols_for_image(rebindings_head, (const struct mach_header *) header, slide);
if (rebindings_head->rebindings) {

This comment has been minimized.

Copy link
@megCanicalKb

megCanicalKb Apr 2, 2018

Contributor

Sadly fixing this leak is also introducing a nullptr dereference.
To fix it we can add a nullptr check

Report from Infer static analysis:
rcd_fishhook.c:186:5: 'rebindings_head' initialized to a null pointer value
rcd_fishhook.c:187:18: Calling 'rcd_prepend_rebindings'
rcd_fishhook.c:60:1: Entered call from 'rcd_rebind_symbols_image'
rcd_fishhook.c:64:7: Assuming 'new_entry' is null
rcd_fishhook.c:187:18: Returning from 'rcd_prepend_rebindings'
rcd_fishhook.c:189:9: Access to field 'rebindings' results in a dereference of a null pointer (loaded from variable 'rebindings_head')

free(rebindings_head->rebindings);
}
free(rebindings_head);
return retval;
}
Expand Down

0 comments on commit 06cfb58

Please sign in to comment.