- config file parser dynamically allocates linebuffer to allow multithreaded applications (#484)

pull/487/head
Michael Zillgith 2 years ago
parent e7c2e37ad4
commit aacf853876

@ -31,8 +31,6 @@
#define READ_BUFFER_MAX_SIZE 1024 #define READ_BUFFER_MAX_SIZE 1024
static uint8_t lineBuffer[READ_BUFFER_MAX_SIZE];
static int static int
readLine(FileHandle fileHandle, uint8_t* buffer, int maxSize) readLine(FileHandle fileHandle, uint8_t* buffer, int maxSize)
{ {
@ -118,6 +116,11 @@ ConfigFileParser_createModelFromConfigFileEx(const char* filename)
IedModel* IedModel*
ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle) ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle)
{ {
uint8_t* lineBuffer = (uint8_t*)GLOBAL_MALLOC(READ_BUFFER_MAX_SIZE);
if (lineBuffer == NULL)
goto exit_error;
int bytesRead = 1; int bytesRead = 1;
bool stateInModel = false; bool stateInModel = false;
@ -541,8 +544,6 @@ ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle)
else else
goto exit_error; goto exit_error;
} }
} }
else { else {
if (StringUtils_startsWith((char*) lineBuffer, "MODEL{")) { if (StringUtils_startsWith((char*) lineBuffer, "MODEL{")) {
@ -564,14 +565,18 @@ ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle)
} }
} }
GLOBAL_FREEMEM(lineBuffer);
return model; return model;
exit_error: exit_error:
GLOBAL_FREEMEM(lineBuffer);
if (DEBUG_IED_SERVER) if (DEBUG_IED_SERVER)
printf("IED_SERVER: error parsing line %i (indentation level = %i)\n", currentLine, indendation); printf("IED_SERVER: error parsing line %i (indentation level = %i)\n", currentLine, indendation);
IedModel_destroy(model); IedModel_destroy(model);
return NULL; return NULL;
} }

Loading…
Cancel
Save