Fix crash on startup
The Avro file was initialized in the wrong order and uninitialized values were used.
This commit is contained in:
@ -190,25 +190,35 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename)
|
|||||||
|
|
||||||
MAXAVRO_FILE* avrofile = calloc(1, sizeof(MAXAVRO_FILE));
|
MAXAVRO_FILE* avrofile = calloc(1, sizeof(MAXAVRO_FILE));
|
||||||
char *my_filename = strdup(filename);
|
char *my_filename = strdup(filename);
|
||||||
char *schema = read_schema(avrofile);
|
|
||||||
|
|
||||||
if (avrofile && my_filename && schema)
|
if (avrofile && my_filename)
|
||||||
{
|
{
|
||||||
avrofile->file = file;
|
avrofile->file = file;
|
||||||
avrofile->filename = my_filename;
|
avrofile->filename = my_filename;
|
||||||
avrofile->schema = maxavro_schema_alloc(schema);
|
|
||||||
avrofile->last_error = MAXAVRO_ERR_NONE;
|
avrofile->last_error = MAXAVRO_ERR_NONE;
|
||||||
|
|
||||||
if (avrofile->schema &&
|
char *schema = read_schema(avrofile);
|
||||||
maxavro_read_sync(file, avrofile->sync) &&
|
|
||||||
maxavro_read_datablock_start(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
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to initialize avrofile.");
|
|
||||||
maxavro_schema_free(avrofile->schema);
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,8 +235,6 @@ MAXAVRO_FILE* maxavro_file_open(const char* filename)
|
|||||||
avrofile = NULL;
|
avrofile = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(schema);
|
|
||||||
|
|
||||||
return avrofile;
|
return avrofile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user