Last active
October 23, 2016 03:20
-
-
Save JZHeadley/c5f614ba9c3182775372418fc428b91d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "malloc-support.h" | |
| int main() { | |
| int *ptr = malloc(sizeof(int)); | |
| if (ptr == NULL) { | |
| printf("couldn't malloc an int"); | |
| return 1; | |
| } | |
| *ptr = 1; | |
| *ptr = 100; | |
| free(ptr); | |
| printf("freed the int after assigning it a value"); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INCLUDES=-I. | |
| CC=gcc | |
| CFLAGS=-I. -c -g -Wall $(INCLUDES) | |
| FLAGS = -O0 -W -Wall -Wextra -g | |
| LINKARGS=-lm | |
| LIBS=-lm | |
| # Productions | |
| all : assign2 | |
| assign2 : assign2.o malloc.so | |
| $(CC) $(LINKARGS) $^ -o $@ $(LIBS) | |
| malloc.so: malloc-support.c malloc-support.h | |
| $(CC) $^ $(FLAGS) -o $@ -shared -fPIC | |
| assign2.o : assign2.c malloc-support.h | |
| $(CC) $< $(CFLAGS) -o $@ | |
| clean : | |
| rm -f malloc.so assign2.o assign2 | |
| run : | |
| valgrind ./assign2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <assert.h> | |
| #include <string.h> | |
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #ifndef MALLOC_SUPPORT_H_ | |
| #define MALLOC_SUPPORT_H_ | |
| struct block_meta; | |
| struct block_meta *find_free_block(struct block_meta **last, size_t size); | |
| struct block_meta *request_space(struct block_meta *last, size_t size); | |
| struct block_meta *get_block_ptr(void *ptr); | |
| void *nofree_malloc(size_t size); | |
| void *malloc(size_t size); | |
| void *calloc(size_t nelem, size_t elsize); | |
| void free(void *ptr); | |
| void *realloc(void *ptr, size_t size); | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment