void *malloc(size_t size) { void *ptr; ptr = mallocp(size); dprintf(fd, "x%lx = malloc(%zu);\n", (unsigned long)ptr, size); return ptr; }
t_hc *create_hc_elem(char *content) { t_hc *elem; elem = mallocp(sizeof(t_hc)); elem->content = content; elem->next = NULL; return (elem); }
t_fd *create_fd(int fd, int fd_pointe) { t_fd *elem; elem = (t_fd*)mallocp(sizeof(t_fd)); elem->next = NULL; elem->fd = fd; elem->fd_pointe = fd_pointe; return (elem); }
void *ft_memalloc(size_t size) { void *alloc; alloc = mallocp(size); if (!alloc) return (NULL); ft_memset(alloc, 0, size); return (alloc); }
char *delete_char(char *str, int index) { char *ret; ret = (char*)mallocp(sizeof(char) * ft_strlen(str)); ft_strncpy(ret, str, index - 1); ft_strcpy(ret + index - 1, str + index); free(str); return (ret); }
char *insert_char(char *str, int index, char c) { char *ret; ret = (char*)mallocp(sizeof(char) * (ft_strlen(str) + 2)); ft_strncpy(ret, str, index); ret[index] = c; ft_strcpy(ret + index + 1, str + index); free(str); return (ret); }
char *ft_strnew(size_t size) { size_t i; char *res; res = (char*)mallocp(size); if (!res) return (NULL); i = 0; while (i < size) res[i++] = '\0'; return (res); }
static t_gnl *gnl_add_elem(t_gnl **list, const int fd) { t_gnl *beginning; t_gnl *elem; elem = mallocp(sizeof(t_gnl)); elem->fd = fd; elem->line = NULL; elem->next = NULL; if (!(*list)) { *list = elem; return (elem); } beginning = (*list); while ((*list)->next) (*list) = (*list)->next; (*list)->next = elem; *list = beginning; return (elem); }
void *malloc(size_t size) { debugWatchman(); #ifdef DEBUG puts("malloc(...)"); #endif static void *(*mallocp)(size_t size); char *error; void *ptr; /* get address of libc malloc */ if (!mallocp) { mallocp = dlsym(RTLD_NEXT, "malloc"); if ((error = dlerror()) != NULL) { fputs(error, stderr); exit(1); } } ptr = mallocp(size); #ifdef DEBUG printf("malloc(%d) = %p\n", size, ptr); #endif //**********************************************// //**********************************************// // Protected section // //**********************************************// //**********************************************// if(executionCanary == 0x0){ srand(time(NULL)); executionCanary = rand() % UINT_MAX; } if(numCanaries != ___MAX_CANARIES && canaryOverflow == 0){ ___canaries[numCanaries] = (unsigned long*)mallocp(2*sizeof(unsigned long)); if (NULL != ___canaries[numCanaries]){ *___canaries[numCanaries] = executionCanary; #ifdef DEBUG_HEAP_CANARIES printf("made heap canary %x @ 0x%x size %x\n", executionCanary, ___canaries[numCanaries], sizeof(unsigned long)); #endif //DEBUG_HEAP_CANARIES numCanaries++; } } else{ canaryOverflow++; } //**********************************************// //**********************************************// // End protected section // //**********************************************// //**********************************************// #ifdef DEBUG printf("malloc(%d) = %p\n", size, ptr); #endif return ptr; }