aboutsummaryrefslogtreecommitdiffstats
path: root/util/cbfstool/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool/common.c')
-rw-r--r--util/cbfstool/common.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index e8c2ccc45..cdc04f333 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -57,6 +57,7 @@ static off_t get_file_size(FILE *f)
int buffer_create(struct buffer *buffer, size_t size, const char *name)
{
buffer->name = strdup(name);
+ buffer->offset = 0;
buffer->size = size;
buffer->data = (char *)malloc(buffer->size);
if (!buffer->data) {
@@ -73,6 +74,7 @@ int buffer_from_file(struct buffer *buffer, const char *filename)
perror(filename);
return -1;
}
+ buffer->offset = 0;
buffer->size = get_file_size(fp);
if (buffer->size == -1u) {
fprintf(stderr, "could not determine size of %s\n", filename);
@@ -116,9 +118,10 @@ void buffer_delete(struct buffer *buffer)
buffer->name = NULL;
}
if (buffer->data) {
- free(buffer->data);
+ free(buffer->data - buffer->offset);
buffer->data = NULL;
}
+ buffer->offset = 0;
buffer->size = 0;
}