Code Monkey home page Code Monkey logo

ft_mallocator's Introduction

THIS PROJECT IS DEPRECATED AND NO LONGER MAINTAINED

This project is deprecated in profit of funcheck which is more easy to use and more powerful.


Logo

Test your allocs protections and leaks ! Report Bug · Request Feature

Table of Contents
  1. About The Tool
  2. Getting Started
  3. Usage
  4. Contributing
  5. Contact

About The Tool

screenshot

This tool allows you to test if every allocs in your project are protected. It also checks if an alloc fail: if you free every allocation.

It also checks leaks !

(back to top)

Getting Started

Here, you will see how to setup this tool in an example project.

Prerequisites

This is working out of the box on 42's dump.

You must compile using clang

At home, you will need those installed on your system :

sudo apt install make clang

Quickstart

  1. Clone the repo inside your project
    git clone https://github.com/tmatis/ft_mallocator.git
  2. Cd in directory
    cd ./ft_mallocator
  3. Execute script
    bash test.sh
  4. Follow script's instructions...

Demo video

record.mp4

(back to top)

Usage

Here we have an example of not well protected code:

char *malloc_function(void)
{
	return (malloc(1000));
}

int main(void)
{
	void *ptr = malloc_function();
	if (ptr == NULL)
		return (1);
	free(ptr);

	void *array[10];

	for (int i = 0; i < 10; i++)
	{
		array[i] = malloc(1000);
		if (array[i] == NULL)
		{
			printf("it fail %i\n", i);
			return (0);
		}
		memset(array[i], 0, 1000);
	}
	
	for (int i = 0; i < 10; i++)
		free(array[i]);

	ptr = malloc_function();
	memset(ptr, 0, 1000);
	free(ptr);
}

This example have many problems, let's run mallocator on it : screenshot

The first allocation is well protected, nothing to say. The second allocation is protected but if a malloc fails, not everything is freed (the program returns without freeing the previous allocations). The third allocation is not protected at all, there is no null check.

Let's see a well protected example:

char *malloc_function(void)
{
	return (malloc(1000));
}

int main(void)
{
	void *ptr = malloc_function();
	if (ptr == NULL)
		return (1);
	free(ptr);

	void *array[10];

	int i = 0;
	for (i = 0; i < 10; i++)
	{
		array[i] = malloc(1000);
		if (array[i] == NULL)
		{
			printf("it fail %i\n", i);
			break ;
		}
		memset(array[i], 0, 1000);
	}
	for (int j = 0; j < i; j++)
		free(array[j]);

	ptr = malloc_function();
	if (!ptr)
		return (1);
	memset(ptr, 0, 1000);
	free(ptr);
}

Then we run mallocator on this code :

screenshot

This code is protected.

You can see how it is working behind the scene here.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

tmatis's 42 stats

(back to top)

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.