Implemented lz_da_remove and a memory analysis tool
This commit is contained in:
parent
5bb6ab1d1b
commit
5a41640054
3 changed files with 131 additions and 0 deletions
34
examples/leak.c
Normal file
34
examples/leak.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#define LZ_MEM_ANALYZER
|
||||
#define LAZY_IMPL
|
||||
#include "../lazy.h"
|
||||
|
||||
typedef struct {
|
||||
int payload;
|
||||
void *next;
|
||||
} LLNode;
|
||||
|
||||
int main () {
|
||||
LLNode *root = malloc(sizeof(LLNode));
|
||||
|
||||
LLNode *curr = root;
|
||||
int prevX = 0;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
LLNode *new = malloc(sizeof(LLNode));
|
||||
curr->next = new;
|
||||
new->payload = ++prevX;
|
||||
curr = new;
|
||||
}
|
||||
|
||||
curr = root;
|
||||
while (curr->next) {
|
||||
void *next = curr->next;
|
||||
printf("%d\n", curr->payload);
|
||||
free(curr);
|
||||
curr = next;
|
||||
}
|
||||
free(curr);
|
||||
|
||||
lz_mem_debug();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue