treebird/src/memory.c
nekobit 1bcd944584 Add bugs
FossilOrigin-Name: aad31b66d4026159283cb42fe630a61d892565c3a0d95a90de7bca7aaf6be9a8
2022-11-14 14:18:35 +00:00

57 lines
977 B
C

/*
* Treebird - Lightweight frontend for Pleroma
*
* Licensed under the BSD 2-Clause License
*/
#include <stdlib.h>
#include <malloc.h>
#include "memory.h"
#ifdef __GLIBC__
#include <malloc.h>
#endif
int tb_memory_allocated_est;
int tb_memory_allocated;
int tb_memory_free;
int tb_memory_times_allocated;
int tb_memory_times_freed;
#ifdef __GLIBC__
void propagate_memory()
{
struct mallinfo2 inf = mallinfo2();
tb_memory_free = inf.fordblks;
tb_memory_allocated = inf.uordblks;
}
#endif // __GLIBC__
void* tb_malloc(size_t size)
{
tb_memory_allocated_est += size;
++tb_memory_times_allocated;
return malloc(size);
}
// Nothing....
void* tb_calloc(size_t nmemb, size_t size)
{
tb_memory_allocated_est = size * nmemb;
return calloc(nmemb, size);
}
void* tb_realloc(void* ptr, size_t size)
{
tb_memory_allocated_est = size;
return realloc(ptr, size);
}
void tb_free(void* ptr)
{
++tb_memory_times_freed;
free(ptr);
}