Giter Site home page Giter Site logo

noleaks's Introduction

noleaks ✅

No memory leaks in c. Are you tempted? 😎

Introduction

Personally, I hate memory leaks! It's too easy a mistake, too difficult to detect and far too fatal.

That's why I've coded a small library that will detect your memory leaks. So you don't have to worry about it.

TOO GOOD ISN'T IT?!

Docs

Simple and effective you know malloc? you know free? prefix with nl and do as usual 😎.

Add a small debugging function to find out where the leaks are, and you've got the solution.

⚠️ with large memory values in multithreaded mode, some bugs have yet to be resolved.

Prototype :

void *nlmalloc(size_t size);
void nlfree(void *ptr);
void check_memory_leaks(void);

Exemple

#include "./include/noleaks.h"

int	main(void)
{
	int	*array;

	// Allocation de mémoire pour un tableau de 10 entiers
	array = (int *)nlmalloc(10 * sizeof(int));
	// Vérification si l'allocation a réussi
	if (array == NULL)
	{
		ft_printf("Erreur d'allocation de mémoire\n");
		return (1);
	}
	// Remplissage du tableau avec des valeurs
	for (int i = 0; i < 10; i++)
	{
		array[i] = i;
	}
	// Affichage des valeurs du tableau
	for (int i = 0; i < 10; i++)
	{
		ft_printf("%d ", array[i]);
	}
	ft_printf("\n");
	// Libération de la mémoire allouée
	// nlfree(array);
	// (Optionnel) Vérification des fuites de mémoire à la fin du programme
	check_memory_leaks();
	return (0);
}

result:

resulat sans free

if you uncomment "nlfree()".

resulat sans free

Usage

git clone [email protected]:arnaudderison/noleaks.git noleaks

OR

git clone https://github.com/arnaudderison/noleaks.git noleaks
cd noleaks
make

Compilation

gcc <your c file> noleaks.a -o <output file>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.