/memcheck.h (e94eea0e33ef14bb69ed5f2505f6c3c1c84bc52e) (1650 bytes) (mode 100644) (type blob)

#ifndef MEM_CHECK
#define MEM_CHECK

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef MEMORY_CHECK
#define MEMORY_CHECK 1
#endif

#if(MEMORY_CHECK==1)
//This is defined globally.
extern FILE* fp_mem_log;

//Place this with the global variables in your .c files
#define MEMCHECK_GLOBAL_VARS	FILE* fp_mem_log;

#define MEMCHECK_CALLOC(data, type, nmemb, size) {\
				data = (type)calloc(nmemb, size);\
				fprintf(fp_mem_log,"a%p,0x0\n",(void*)data);\
				}

#define MEMCHECK_MALLOC(data, type, size) {\
				data = (type)malloc(size);\
				fprintf(fp_mem_log,"a%p,0x0\n",(void*)data);\
				}

#define MEMCHECK_REALLOC(data_out, type, data_in, size) {\
					fprintf(fp_mem_log,"r%p,",(void*)data_in);\
					data_out = (type)realloc(data_in,size);\
					fprintf(fp_mem_log,"%p\n",(void*)data_out);\
					}

#define MEMCHECK_FREE(data) {\
				fprintf(fp_mem_log,"f%p,0x0\n",(void*)data);\
				free(data);\
				}

#define MEMCHECK_INIT() {\
			fp_mem_log = fopen("mem_check.log","w");\
			if(fp_mem_log == NULL){\
				printf("Unable to open log file. errno: %d\n",errno);\
				return -1;\
			}\
			setbuf(fp_mem_log,NULL);\
		}

#define MEMCHECK_CLOSE() {\
				fclose(fp_mem_log);\
				}

#else

#define MEMCHECK_GLOBAL_VARS

#define MEMCHECK_CALLOC(data, type, nnmemb, size) {\
				data = (type)calloc(nmemb, size);\
				}

#define MEMCHECK_MALLOC(data, type, size) {\
				data = (type)malloc(size);\
				}

#define MEMCHECK_REALLOC(data_out, type, data_in, size) {\
					data_out = (type)realloc(data_in,size);\
					}

#define MEMCHECK_FREE(data) {\
				free(data);\
				};

#define MEMCHECK_INIT
#define MEMCHECK_CLOSE
#endif

#endif


Mode Type Size Ref File
100644 blob 1466 fd5b575c6ec27a39901eb2595eb795eab1c8fe81 README
100644 blob 4554 e0372fdd15b80632dfc7cb606f697dc0cf6d87c4 mem_check_scanner.c
100644 blob 1650 e94eea0e33ef14bb69ed5f2505f6c3c1c84bc52e memcheck.h
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/ORpKTKoVQnFhs/Memory_Check

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/ORpKTKoVQnFhs/Memory_Check

Clone this repository using git:
git clone git://git.rocketgit.com/user/ORpKTKoVQnFhs/Memory_Check

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main