Fix crash on startup

The Avro file was initialized in the wrong order and uninitialized values
were used.
This commit is contained in:
Markus Mäkelä
2017-01-27 12:55:07 +02:00
parent 8da655b7cb
commit 81b9d51aab

View File

@ -190,15 +190,19 @@ 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;
char *schema = read_schema(avrofile);
if (schema)
{
avrofile->schema = maxavro_schema_alloc(schema);
if (avrofile->schema &&
maxavro_read_sync(file, avrofile->sync) &&
maxavro_read_datablock_start(avrofile))
@ -211,6 +215,12 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename)
maxavro_schema_free(avrofile->schema);
error = true;
}
free(schema);
}
else
{
error = true;
}
}
else
{
@ -225,8 +235,6 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename)
avrofile = NULL;
}
free(schema);
return avrofile;
}