diff options
-rw-r--r-- | util/cbfstool/common.c | 2 | ||||
-rw-r--r-- | util/cbfstool/common.h | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index 44836ab6d7..09a7449c15 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -115,7 +115,7 @@ void buffer_delete(struct buffer *buffer) buffer->name = NULL; } if (buffer->data) { - free(buffer->data - buffer->offset); + free(buffer_get_original_backing(buffer)); buffer->data = NULL; } buffer->offset = 0; diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h index b61c2c0a5e..561a17abe3 100644 --- a/util/cbfstool/common.h +++ b/util/cbfstool/common.h @@ -120,6 +120,14 @@ static inline bool buffer_check_magic(const struct buffer *b, const char *magic, memcmp(b->data, magic, magic_len) == 0; } +/* Returns the start of the underlying buffer, with the offset undone */ +static inline void *buffer_get_original_backing(const struct buffer *b) +{ + if (!b) + return NULL; + return b->data - b->offset; +} + /* Creates an empty memory buffer with given size. * Returns 0 on success, otherwise non-zero. */ int buffer_create(struct buffer *buffer, size_t size, const char *name); |