mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
828 stars 444 forks source link

config_file_parser.c use a static var and not multithread #484

Closed Ptlia closed 6 months ago

Ptlia commented 7 months ago

lineBuffer is declare as static, and cannot parse a model in multhreading-multiserver environnment when them parse in same time.

Juste declare with GLOBAL_ALLOC in beginning of funciton and free at the end

// Begin uint8_t lineBuffer = (uint8_t) GLOBAL_MALLOC(READ_BUFFER_MAX_SIZE * sizeof(uint8_t)); if (lineBuffer == NULL) goto exit_error;

// End

GLOBAL_FREEMEM(lineBuffer); return model;

exit_error: if (DEBUG_IED_SERVER) printf("IED_SERVER: error parsing line %i (indentation level = %i)\n", currentLine, indendation);

GLOBAL_FREEMEM(lineBuffer);
if (model != NULL)
    IedModel_destroy(model);
return NULL;
mzillgith commented 6 months ago

Thanks for the hint. I updated the code to use dynamic memory instead the global static variable.