/leak_finder

Spin off of my malloc project @ 42 Network, to help finding leaks

Primary LanguageC

42

Leak Finder

Development repository for the leak finder utility developed @ 42 Heilbronn

GitHub code size in bytes GitHub top language GitHub top language GitHub last commit


This is a project built on top of ft_malloc to help find leaks on other projects.


Usage

  1. clone this repo.
# clone this repo.
$ git clone git@github.com:iwillenshofer/leak_finder.git
$ make
  1. 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

Example of main() file

#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);
}

Included Functions

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);