Adding malloc and free function that reaffect the ptr to NULL
This commit is contained in:
parent
fbc9544386
commit
2a664856dc
|
@ -12,6 +12,7 @@ find_package(Gint 2.9 REQUIRED)
|
|||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/malloc.c
|
||||
src/game.c
|
||||
src/linked_list.c
|
||||
src/texture_manager.c
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include <gint/kmalloc.h>
|
||||
#include "linked_list.h"
|
||||
|
||||
#include <gint/display.h>
|
||||
#include "malloc.h"
|
||||
|
||||
void linked_list_init(linked_list_t *linked_list, const size_t data_size)
|
||||
{
|
||||
|
@ -13,13 +11,13 @@ void linked_list_init(linked_list_t *linked_list, const size_t data_size)
|
|||
elem_t *elem_create(linked_list_t *linked_list)
|
||||
{
|
||||
elem_t *elem;
|
||||
elem = kmalloc(sizeof(elem_t), NULL);
|
||||
elem = malloc(sizeof(elem_t));
|
||||
if(!elem) return NULL;
|
||||
|
||||
elem->data = kmalloc(linked_list->data_size, NULL);
|
||||
elem->data = malloc(linked_list->data_size);
|
||||
if(!elem->data)
|
||||
{
|
||||
kfree(elem);
|
||||
free(elem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -68,12 +66,8 @@ void linked_list_pop_back(linked_list_t *linked_list)
|
|||
else
|
||||
linked_list->first = NULL;
|
||||
|
||||
kfree(tmp->data);
|
||||
kfree(tmp);
|
||||
if(tmp != NULL)
|
||||
{
|
||||
dtext(80, 80, C_RED, "WHAT THE HELLL ??");
|
||||
}
|
||||
free(tmp->data);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void linked_list_pop_front(linked_list_t *linked_list)
|
||||
|
@ -88,8 +82,8 @@ void linked_list_pop_front(linked_list_t *linked_list)
|
|||
else
|
||||
linked_list->last = NULL;
|
||||
|
||||
kfree(tmp->data);
|
||||
kfree(tmp);
|
||||
free(tmp->data);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
size_t linked_list_get_size(linked_list_t *linked_list)
|
||||
|
|
|
@ -17,9 +17,9 @@ int main(void)
|
|||
}
|
||||
*/
|
||||
|
||||
#include <gint/kmalloc.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include "malloc.h"
|
||||
#include "linked_list.h"
|
||||
|
||||
int main(void)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include "malloc.h"
|
||||
|
||||
inline void *malloc(size_t size)
|
||||
{
|
||||
return kmalloc(size, NULL);
|
||||
}
|
||||
|
||||
inline void free(void *ptr)
|
||||
{
|
||||
kfree(ptr);
|
||||
ptr = NULL;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef MALLOC_H
|
||||
#define MALLOC_H
|
||||
|
||||
#include <gint/kmalloc.h>
|
||||
|
||||
/* malloc(): Just call kmalloc from gint/kmalloc.h.
|
||||
|
||||
@size Size of requested block
|
||||
Returns address of allocated block, NULL on error. */
|
||||
inline void *malloc(size_t size);
|
||||
|
||||
/* malloc(): Just call kmalloc from gint/kmalloc.h.
|
||||
|
||||
@ptr Pointer to free
|
||||
Free given ptr and reafect to NULL. */
|
||||
inline void free(void *ptr);
|
||||
|
||||
#endif // MALLOC_H
|
Loading…
Reference in New Issue