simplify memory cleanup & free
This commit is contained in:
@@ -1285,9 +1285,7 @@ CyberiadaDocument* cyberiada_new_sm_document(void)
|
|||||||
int cyberiada_init_sm_document(CyberiadaDocument* doc)
|
int cyberiada_init_sm_document(CyberiadaDocument* doc)
|
||||||
{
|
{
|
||||||
if (doc) {
|
if (doc) {
|
||||||
doc->format = NULL;
|
memset(doc, 0, sizeof(CyberiadaDocument));
|
||||||
doc->meta_info = NULL;
|
|
||||||
doc->state_machines = NULL;
|
|
||||||
}
|
}
|
||||||
return CYBERIADA_NO_ERROR;
|
return CYBERIADA_NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -4144,21 +4142,23 @@ int cyberiada_write_sm_document(CyberiadaDocument* doc, const char* filename, Cy
|
|||||||
writer = xmlNewTextWriterFilename(filename, 0);
|
writer = xmlNewTextWriterFilename(filename, 0);
|
||||||
if (!writer) {
|
if (!writer) {
|
||||||
ERROR("cannot open xml writter for file %s\n", filename);
|
ERROR("cannot open xml writter for file %s\n", filename);
|
||||||
|
xmlCleanupParser();
|
||||||
return CYBERIADA_XML_ERROR;
|
return CYBERIADA_XML_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
res = xmlTextWriterStartDocument(writer, NULL, GRAPHML_XML_ENCODING, NULL);
|
res = xmlTextWriterStartDocument(writer, NULL, GRAPHML_XML_ENCODING, NULL);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
ERROR("error writing xml start document: %d\n", res);
|
ERROR("error writing xml start document: %d\n", res);
|
||||||
xmlFreeTextWriter(writer);
|
res = CYBERIADA_XML_ERROR;
|
||||||
return CYBERIADA_XML_ERROR;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == cybxmlYED) {
|
if (format == cybxmlYED) {
|
||||||
if (!doc->state_machines || doc->state_machines->next) {
|
if (!doc->state_machines || doc->state_machines->next) {
|
||||||
ERROR("YED format supports only single SM documents\n");
|
ERROR("YED format supports only single SM documents\n");
|
||||||
xmlFreeTextWriter(writer);
|
res = CYBERIADA_BAD_PARAMETER;
|
||||||
return CYBERIADA_BAD_PARAMETER;
|
break;
|
||||||
}
|
}
|
||||||
res = cyberiada_write_sm_document_yed(doc, writer);
|
res = cyberiada_write_sm_document_yed(doc, writer);
|
||||||
} else if (format == cybxmlCyberiada10) {
|
} else if (format == cybxmlCyberiada10) {
|
||||||
@@ -4166,18 +4166,25 @@ int cyberiada_write_sm_document(CyberiadaDocument* doc, const char* filename, Cy
|
|||||||
}
|
}
|
||||||
if (res != CYBERIADA_NO_ERROR) {
|
if (res != CYBERIADA_NO_ERROR) {
|
||||||
ERROR("error writing xml %d\n", res);
|
ERROR("error writing xml %d\n", res);
|
||||||
xmlFreeTextWriter(writer);
|
res = CYBERIADA_XML_ERROR;
|
||||||
return CYBERIADA_XML_ERROR;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = xmlTextWriterEndDocument(writer);
|
res = xmlTextWriterEndDocument(writer);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
ERROR("error writing xml end document: %d\n", res);
|
ERROR("error writing xml end document: %d\n", res);
|
||||||
xmlFreeTextWriter(writer);
|
res = CYBERIADA_XML_ERROR;
|
||||||
return CYBERIADA_XML_ERROR;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = CYBERIADA_NO_ERROR;
|
||||||
|
} while (0);
|
||||||
|
|
||||||
xmlFreeTextWriter(writer);
|
xmlFreeTextWriter(writer);
|
||||||
|
|
||||||
|
if (res != CYBERIADA_NO_ERROR) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
return CYBERIADA_NO_ERROR;
|
return CYBERIADA_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user