Changeset 1104 in MondoRescue for branches/stable/mondo/src/lib/mr_mem.c
- Timestamp:
- Feb 7, 2007, 8:00:23 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/lib/mr_mem.c
r1064 r1104 22 22 /* 23 23 * Function that frees memory if necessary 24 * A pointer to the memory pointed is passed to it. 25 * *allocated variable points then to the original content 26 * pointed to by the caller 24 27 */ 25 void mr_free (void *allocated) {28 void mr_free_int(void **allocated, int line, const char *file) { 26 29 27 30 /* free man pages says that if allocated is NULL 28 31 * nothing happens 29 32 */ 30 free(allocated); 31 allocated = NULL; 33 if (*allocated != NULL) { 34 free(*allocated); 35 *allocated = NULL; 36 } else { 37 mr_msg_int(0,line,file,"Attempt to reference NULL pointer\nExiting..."); 38 mr_exit(-1,"Attempt to reference NULL pointer"); 39 } 32 40 } 33 41 34 42 /* encapsulation function for malloc */ 35 void *mr_malloc (size_t size) {43 void *mr_malloc_int(size_t size, int line, const char *file) { 36 44 37 45 void *ret; … … 39 47 ret = malloc(size); 40 48 if (ret == NULL) { 41 mr_log_exit(-1,"Unable to alloc memory in mr_malloc\nExiting..."); 49 mr_msg_int(0,line,file,"Unable to alloc memory in mr_malloc\nExiting..."); 50 mr_exit(-1,"Unable to alloc memory in mr_malloc"); 42 51 } 43 52 return(ret); … … 45 54 46 55 /* encapsulation function for getline */ 47 void mr_getline (char **lineptr, size_t *n, FILE *stream) {56 void mr_getline_int(char **lineptr, size_t *n, FILE *stream, int line, const char *file) { 48 57 49 58 ssize_t ret; … … 51 60 ret = getline(lineptr,n,stream); 52 61 if (ret == -1) { 53 mr_log_exit(-1,"Unable to alloc memory in mr_getline\nExiting..."); 62 mr_msg_int(0,line,file,"Unable to alloc memory in mr_getline\nExiting...",line,file); 63 mr_exit(-1,"Unable to alloc memory in mr_getline"); 54 64 } 55 65 } 56 66 57 67 /* encapsulation function for asprintf */ 58 void mr_asprintf (char **strp, const char *fmt, ...) {68 void mr_asprintf_int(char **strp, int line, const char *file, const char *fmt, ...) { 59 69 60 70 int res = 0; … … 64 74 res = vasprintf(strp, fmt, args); 65 75 if (res == -1) { 66 mr_log_exit(-1,"Unable to alloc memory in mr_asprintf\nExiting..."); 76 mr_msg_int(0,line,file,"Unable to alloc memory in mr_asprintf\nExiting...",line,file); 77 mr_exit(-1,"Unable to alloc memory in mr_asprintf"); 67 78 } 68 79 va_end(args); … … 73 84 * freeing it before in any case 74 85 */ 75 void mr_allocstr (char *alloc, const char *orig) {86 void mr_allocstr_int(char *alloc, const char *orig, int line, const char *file) { 76 87 77 mr_free ((void *)alloc);78 mr_asprintf (&alloc, orig);88 mr_free_int((void **)&alloc, line, file); 89 mr_asprintf_int(&alloc, line, file, orig); 79 90 }
Note:
See TracChangeset
for help on using the changeset viewer.