From 81b9d51aab460300f87f119337e2dad4d71ac6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 27 Jan 2017 12:55:07 +0200 Subject: [PATCH] Fix crash on startup The Avro file was initialized in the wrong order and uninitialized values were used. --- avro/maxavro_file.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/avro/maxavro_file.c b/avro/maxavro_file.c index 0f77794df..7c5083489 100644 --- a/avro/maxavro_file.c +++ b/avro/maxavro_file.c @@ -190,25 +190,35 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename) MAXAVRO_FILE* avrofile = calloc(1, sizeof(MAXAVRO_FILE)); char *my_filename = strdup(filename); - char *schema = read_schema(avrofile); - if (avrofile && my_filename && schema) + if (avrofile && my_filename) { avrofile->file = file; avrofile->filename = my_filename; - avrofile->schema = maxavro_schema_alloc(schema); avrofile->last_error = MAXAVRO_ERR_NONE; - if (avrofile->schema && - maxavro_read_sync(file, avrofile->sync) && - maxavro_read_datablock_start(avrofile)) + char *schema = read_schema(avrofile); + + if (schema) { - avrofile->header_end_pos = avrofile->block_start_pos; + avrofile->schema = maxavro_schema_alloc(schema); + + if (avrofile->schema && + maxavro_read_sync(file, avrofile->sync) && + maxavro_read_datablock_start(avrofile)) + { + avrofile->header_end_pos = avrofile->block_start_pos; + } + else + { + MXS_ERROR("Failed to initialize avrofile."); + maxavro_schema_free(avrofile->schema); + error = true; + } + free(schema); } else { - MXS_ERROR("Failed to initialize avrofile."); - maxavro_schema_free(avrofile->schema); error = true; } } @@ -225,8 +235,6 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename) avrofile = NULL; } - free(schema); - return avrofile; }