-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfree.c
More file actions
36 lines (32 loc) · 734 Bytes
/
free.c
File metadata and controls
36 lines (32 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
** free.c for free in /home/nasrat_v/rendu/tek2/malloc/PSU_2020_malloc
**
** Made by Valentin Nasraty
** Login <valentin.nasraty@epitech.eu>
**
** Started on Sun Feb 5 17:28:11 2017 Valentin Nasraty
** Last update Sun Feb 12 14:57:28 2017 Valentin Nasraty
*/
#include "malloc.h"
void *base_bloc;
void free(void *ptr)
{
t_bloc *bloc;
trylock_thread();
if (ptr == NULL || (bloc = get_bloc(ptr)) == NULL)
{
unlock_thread();
return;
}
if (bloc->data == ptr && bloc->isFree == false)
{
bloc->isFree = true;
bloc = fusion_free_bloc(bloc);
if (bloc == base_bloc && bloc->next == NULL)
{
brk((char*)bloc + getpagesize());
base_bloc = NULL;
}
}
unlock_thread();
}