Skip to content

Commit

Permalink
- Free the memory properly.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12574 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Aug 17, 2012
1 parent 49d1633 commit 7f96e62
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Compiler/runtime/FMIImpl.c
Expand Up @@ -61,19 +61,10 @@ static void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_statu
#endif
}

static char* generateModelicaCode(fmi1_import_t* fmu, const char* workingDirectory)
static void generateModelicaCode(fmi1_import_t* fmu, char* fileName, const char* workingDirectory)
{
FILE* file;
char* fileName;
// read the model identifier from FMI.
const char* modelIdentifier = fmi1_import_get_model_identifier(fmu);
int len = strlen(workingDirectory) + strlen(modelIdentifier);
fileName = (char*) malloc(len + 16);
strcpy(fileName, workingDirectory);
strcat(fileName, "/");
strcat(fileName, modelIdentifier);
strcat(fileName, "FMUImportNew");
strcat(fileName, ".mo");
// create the Modelica File.
file = fopen(fileName, "w");
if (!file) {
Expand All @@ -98,7 +89,6 @@ static char* generateModelicaCode(fmi1_import_t* fmu, const char* workingDirecto
fprintf(file, "end FMUImportNew_%s;", modelIdentifier);
}
fclose(file);
return fileName;
}

char* FMIImpl__importFMU(const char* fileName, const char* workingDirectory)
Expand Down Expand Up @@ -148,9 +138,21 @@ char* FMIImpl__importFMU(const char* fileName, const char* workingDirectory)
c_add_message(-1, ErrorType_scripting, ErrorLevel_error, gettext("Could not create the DLL loading mechanism(C-API)."), NULL, 1);
return "";
}
char* generatedFileName = generateModelicaCode(fmu, workingDirectory);
// create a file name for generated Modelica code
char* generatedFileName;
// read the model identifier from FMI.
const char* modelIdentifier = fmi1_import_get_model_identifier(fmu);
int len = strlen(workingDirectory) + strlen(modelIdentifier);
generatedFileName = (char*) malloc(len + 16);
strcpy(generatedFileName, workingDirectory);
strcat(generatedFileName, "/");
strcat(generatedFileName, modelIdentifier);
strcat(generatedFileName, "FMUImportNew");
strcat(generatedFileName, ".mo");
// Generate Modelica code and save the file
generateModelicaCode(fmu, generatedFileName, workingDirectory);
fmi1_import_destroy_dllfmu(fmu);
/*fmi1_import_free(fmu);*/ /* Crashes the app */
fmi1_import_free(fmu);
fmi_import_free_context(context);
return generatedFileName;
}
Expand Down

0 comments on commit 7f96e62

Please sign in to comment.