Development repository for the leak finder utility developed @ 42 Heilbronn
This is a project built on top of ft_malloc to help find leaks on other projects.
- clone this repo.
# clone this repo.
$ git clone git@github.com:iwillenshofer/leak_finder.git
$ make
- Add the
malloc.h
header as the first header in your project.
# add as the first header in your project
#include "malloc.h"
#set this to the folder you cloned the repo, relative to your project
$ export LEAK_FINDER=./leak_finder
$ gcc -L./${LEAK_FINDER} -lft_malloc -I./${LEAK_FINDER}/includes main.c
$ ./a.out
#include "malloc.h"
#include <string.h>
#include <stdio.h>
int main(void)
{
char *s;
char *string = "hello world";
size_t size = strlen(string);
s = malloc(size + 1);
s[size] = '\0';
memcpy(s, string, size);
printf("Malloc'd string: %s\n", s);
show_alloc_mem_ex();
print_leaks();
free(s);
return (0);
}
name | prototype |
---|---|
malloc | void *malloc(size_t size); |
realloc | void *realloc(void *ptr, size_t size); |
free | void free(void *ptr); |
show_alloc_mem | void show_alloc_mem(void); |
show_alloc_mem_ex | void show_alloc_mem_ex(void); |
print_leaks | void print_leaks(void); |