AmendHub

Download:

jcs

/

subtext

/

amendments

/

228

bile: Better malloc notes


jcs made amendment 228 over 2 years ago
--- bile.c Sun Jul 31 22:37:40 2022 +++ bile.c Wed Aug 3 13:59:30 2022 @@ -15,6 +15,7 @@ */ #include <string.h> +#include <stdio.h> #include "bile.h" #include "util.h" @@ -270,6 +271,7 @@ bile_find(struct bile *bile, const OSType type, const { struct bile_object *o, *ocopy; unsigned long n; + char note[MALLOC_NOTE_SIZE]; bile_check_sanity(bile); @@ -277,7 +279,9 @@ bile_find(struct bile *bile, const OSType type, const if (o == NULL) return NULL; - ocopy = xmalloc(BILE_OBJECT_SIZE, "bile_find"); + snprintf(note, sizeof(note), "bile_find %s %lu", OSTypeToString(type), + id); + ocopy = xmalloc(BILE_OBJECT_SIZE, note); memcpy(ocopy, o, BILE_OBJECT_SIZE); return ocopy; @@ -345,6 +349,7 @@ bile_get_nth_of_type(struct bile *bile, const unsigned { struct bile_object *o, *ocopy; size_t n, count = 0; + char note[MALLOC_NOTE_SIZE]; bile_check_sanity(bile); @@ -356,7 +361,9 @@ bile_get_nth_of_type(struct bile *bile, const unsigned continue; if (count == index) { - ocopy = xmalloc(BILE_OBJECT_SIZE, "bile_get_nth_of_type"); + snprintf(note, sizeof(note), "bile_get_nth %s %lu", + OSTypeToString(type), index); + ocopy = xmalloc(BILE_OBJECT_SIZE, note); memcpy(ocopy, o, BILE_OBJECT_SIZE); return ocopy; } @@ -570,6 +577,7 @@ bile_read_alloc(struct bile *bile, const OSType type, struct bile_object *o; size_t ret; char **data; + char note[MALLOC_NOTE_SIZE]; bile_check_sanity(bile); @@ -586,7 +594,9 @@ bile_read_alloc(struct bile *bile, const OSType type, return 0; } - *data = xmalloczero(o->size, "bile_read_alloc"); + snprintf(note, sizeof(note), "bile_read_alloc %s %ld", + OSTypeToString(type), id); + *data = xmalloczero(o->size, note); ret = bile_read_object(bile, o, *data, o->size); return ret; @@ -634,7 +644,7 @@ bile_write(struct bile *bile, const OSType type, const short bile_marshall_object(struct bile *bile, const struct bile_object_field *fields, const size_t nfields, - void *object, void *ret_ptr, size_t *ret_size) + void *object, void *ret_ptr, size_t *ret_size, char *note) { char **ret; char *data, *ptr; @@ -689,7 +699,7 @@ iterate_fields: } if (!write) { - data = xmalloc(size, "bile_marshall_object"); + data = xmalloc(size, note); write = true; size = 0; goto iterate_fields; @@ -705,7 +715,7 @@ short bile_unmarshall_object(struct bile *bile, const struct bile_object_field *fields, const size_t nfields, const void *data, const size_t data_size, void *object, - const size_t object_size, bool deep) + const size_t object_size, bool deep, char *note) { size_t off, fsize = 0, n; char *ptr, *dptr; @@ -731,7 +741,7 @@ bile_unmarshall_object(struct bile *bile, memset(ptr, 0, sizeof(dptr)); continue; } - dptr = xmalloc(fsize, "bile_unmarshall_object"); + dptr = xmalloc(fsize, note); memcpy(ptr, &dptr, sizeof(dptr)); ptr = dptr; } --- bile.h Mon Jul 25 15:07:34 2022 +++ bile.h Mon Aug 1 10:07:22 2022 @@ -137,11 +137,11 @@ short bile_verify(struct bile *bile); short bile_marshall_object(struct bile *bile, const struct bile_object_field *fields, const size_t nfields, void *object, - void *ret_ptr, size_t *ret_size); + void *ret_ptr, size_t *ret_size, char *note); short bile_unmarshall_object(struct bile *bile, const struct bile_object_field *fields, const size_t nfields, const void *data, const size_t data_size, void *object, - const size_t object_size, bool deep); + const size_t object_size, bool deep, char *note); #endif