[Axl] axl_doc_parse_from_file aborts program in subfunction
Raphael Schneider
raphael_schneider at web.de
Mon Feb 17 16:54:00 CET 2014
Hi Francis,
thank you very much for your input.
I suspect it's some axl memory allocation bug.
I tried to make a working, rather minimal example. Including a .xml
file. Couldn't exactly reproduce the same error, but now the program
just crashes when it calls axl_node_free(root) in the second
(write_xml() ) function. Which I suspect to be of similar reasons as my
crash before.
In short: Main() calls the function get_xml() which reads some data from
test1.xml. The return value then is used for the second function,
write_xml() which writes some data and saves the updated .xml file. The
crash now occurs in the second function when I try to call
axl_node_free(root).
The full source code is here, and after that the xml file that is used
(test1.xml):
#include <stdio.h>
#include <stdlib.h>
#include <axl.h>
int get_xml(void) {
printf("get_xml() initialized...\n");
//axl objects
axlError *error = NULL;
axlDoc *doc = NULL;
axlNode *root = NULL;
axlNode *node = NULL;
int npump; //number of pumps
//get doc element
doc = axl_doc_parse_from_file("test1.xml", &error);
if (doc == NULL) {
printf("couldn't load axl doc");
axl_error_free(error);
exit(0);
}
//get root and find number of pumps
root = axl_doc_get_root(doc);
node = axl_node_get_child_called(root, "Pumps");
npump = axl_node_get_child_num(node);
//release axl objects
axl_node_free(node);
axl_node_free(root);
axl_error_free(error);
axl_doc_free(doc);
printf(" ...get_xml finished\n");
//return value to function
return npump;
}
void write_xml(int n_pump) {
printf("write_xml() initialized...\n");
//axl objects
axlError *error = NULL;
axl_bool *out;
axlDoc *doc = NULL;
axlNode *root = NULL;
axlNode *node = NULL;
axlNode *flow = NULL;
double fl_d = 123; //flow as double
char fl_s[10]; //flow as string
//get doc element
doc = axl_doc_parse_from_file("test1.xml", &error);
if (doc == NULL) {
printf("couldn't load axl doc");
axl_error_free(error);
exit(0);
}
//write new flow
root = axl_doc_get_root(doc);
node = axl_node_get_child_called(root, "Pumps");
node = axl_node_get_first_child(node); //get first pump
for (int i = 0; i < n_pump; i++) {
sprintf(fl_s, "%f", fl_d); //conververt flow to string
flow = axl_node_get_child_called(node, "Flow"); //get flow node
axl_node_set_is_empty(flow, axl_true); //delete old value
axl_node_set_content(flow, fl_s, -1); //write new value
node = axl_node_get_next(node); //get next pump
}
printf("debug1\n");
//save file
out = axl_doc_dump_pretty_to_file(doc, "test1.xml", 2);
if (out == 0) {
printf("couldn't save file doc");
exit(0);
}
printf("debug2\n");
//release axl objects
axl_node_free(flow);
printf("debug3\n");
axl_node_free(node);
printf("debug4\n");
axl_node_free(root);
printf("debug5\n");
axl_error_free(error);
printf("debug6\n");
axl_doc_free(doc);
printf(" ... write_xml() finished\n");
}
int main(void) {
int npump;
printf("main() - calling get_xml()\n");
npump = get_xml();
printf("main() - calling write_xml()\n");
write_xml(npump);
printf("main() - finished\n");
}
The xml file test1.xml:
<?xml version='1.0' encoding='iso-8859-1' ?>
<XMLExampleModel>
<Station Id='central'>
<Elevation>31.000</Elevation>
<XCoordinate>886.466</XCoordinate>
<YCoordinate>838.855</YCoordinate>
</Station>
<Pumps>
<Pump Id='bla'>
<Elevation>15.000</Elevation>
<XCoordinate>845.466</XCoordinate>
<YCoordinate>898.855</YCoordinate>
<Flow>123.000000</Flow>
</Pump>
<Pump Id='blæ'>
<Elevation>24.500</Elevation>
<XCoordinate>974.230</XCoordinate>
<YCoordinate>743.005</YCoordinate>
<Flow>123.000000</Flow>
</Pump>
</Pumps>
</XMLExampleModel>
Am 17.02.2014 10:16, schrieb Francis Brosnan Blazquez:
>> Hi Francis,
>
> Hi Raphael,
>
>> yes, I missed the & operator. But it unfortunately doesn't make it
>> work...
>>
>> I now suspect it has something to do with the axlDoc/axlNode
>> variables and their release from memory. Why is that? In the program
>> I have another function that also uses axl library in this way, which
>> is called before the function I posted that doesn't work.
>
> The code you posted, in the relation to memory allocation is pefect.
> It cannot break.
> Maybe the document activates a bug inside axl engine. Can you post the
> document that triggers the failure?
>
> Please, remove any sensitive data before posting.
>
>> So, the first time axl library is used it works - the second time it
>> doesn't.
>
> It's hard to tell but if you consider it loads the first time and the
> second breaks, it is a signal for
> something messing internal memory allocation structures. I saw this in
> the past....
>
> ...but the culprit can also be other memory handling errors.
>
> In any case, I recommend you to run your test under valgrind
> supervision to spot the failure.
> It's your best option.
>
>> I use the memory release functions axl_doc_free and so on. That
>> should do the job, no?
>
> Yes but, this has nothing to do with your problem. If you take a look
> at your function, each
> time the document is parsed, a new axlDoc document is loaded...so each
> axl_doc_free
> function is independent...unless you are calling axl_doc_free twice
> over the same variable...
>
> ...which is something that is not shown in your example (your code
> doesn't show where and how
> axl_doc_free is called).
>
>> And in any case the variables are only defined locally. I also
>> already tried using different names for the axl objects in the
>> different functions. Or does it have to do anything with the
>> axl_init() and axl_end() functions? Which are - according to the
>> documentation - not even functional right now?
>
> My impression is that your problem is around some wrong memory
> deallocation somewhere or
> maybe a bug inside axl engine that causes wrong memory
> allocation/deallocation patterns....
>
> ...but it is hard to tell without a full working example. Using
> valgrind to check your program and
> the usage of axl is not doing fancy things with the memory.
>
> Best Regards,
>
>> Best regards
>> Raphael
>>
>> Am 14.02.2014 17:20, schrieb Francis Brosnan Blazquez:
>>
>>> Hi Raphael,
>>>
>>>> I've got a problem with parsing a file. I've got a subfunction that
>>>> starts as stated:
>>>>
>>>> int write_frq(int n_pump, double frqs[]) {
>>>> axlError *a_err = NULL;
>>>>
>>>> axlDoc *doc = NULL; //axl library document object
>>>> axlNode *root = NULL; //axl library root node object
>>>> axlNode *node = NULL; //node object for navigation
>>>>
>>>> printf("DEBUG - write frq() axl variables defined\n");
>>>>
>>>> //get doc reference
>>>> doc = axl_doc_parse_from_file("GAtest1_input.xml", a_err);
>>>
>>> ..this must be:
>>>
>>> doc = axl_doc_parse_from_file ("GAtest1_input.xml", &a_err); // put
>>> an & so you pas a axlErr **
>>>
>>> ...I wonder how your compiler is missing this error :-??
>>>
>>> Best Regards,
>>> --
>>> Francis Brosnan Blázquez <francis.brosnan at aspl.es <mailto:francis.brosnan at aspl.es>>
>>> ASPL
>>> 91 134 14 22 - 91 134 14 45 - 91 116 07 57
>>>
>>> AVISO LEGAL
>>>
>>> Este mensaje se dirige exclusivamente a su destinatario. Los datos
>>> incluidos en el presente correo son confidenciales y sometidos a secreto
>>> profesional, se prohíbe divulgarlos, en virtud de las leyes vigentes. Si
>>> usted no lo es y lo ha recibido por error o tiene conocimiento del mismo
>>> por cualquier motivo, le rogamos que nos lo comunique por este medio y
>>> proceda a destruirlo o borrarlo.
>>>
>>> En virtud de lo dispuesto en la Ley Orgánica 15/1999, de 13 de
>>> diciembre, de Protección de Datos de Carácter Personal, le informamos de
>>> que sus datos de carácter personal, recogidos de fuentes accesibles al
>>> público o datos que usted nos ha facilitado previamente, proceden de
>>> bases de datos propiedad de Advanced Software Production Line, S.L.
>>> (ASPL). No obstante, usted puede ejercitar sus derechos de acceso,
>>> rectificación, cancelación y oposición dispuestos en la mencionada Ley
>>> Orgánica, notificándolo por escrito a:
>>> ASPL - Protección Datos, C/Antonio Suárez 10 A-102, 28802, Alcalá de
>>> Henares (Madrid).
>>>
>>
>> _______________________________________________
>> Axl mailing list
>> Axl at lists.aspl.es <mailto:Axl at lists.aspl.es>
>> http://lists.aspl.es/cgi-bin/mailman/listinfo/axl
>
> --
> Francis Brosnan Blázquez <francis.brosnan at aspl.es <mailto:francis.brosnan at aspl.es>>
> ASPL
> 91 134 14 22 - 91 134 14 45 - 91 116 07 57
>
> AVISO LEGAL
>
> Este mensaje se dirige exclusivamente a su destinatario. Los datos
> incluidos en el presente correo son confidenciales y sometidos a secreto
> profesional, se prohíbe divulgarlos, en virtud de las leyes vigentes. Si
> usted no lo es y lo ha recibido por error o tiene conocimiento del mismo
> por cualquier motivo, le rogamos que nos lo comunique por este medio y
> proceda a destruirlo o borrarlo.
>
> En virtud de lo dispuesto en la Ley Orgánica 15/1999, de 13 de
> diciembre, de Protección de Datos de Carácter Personal, le informamos de
> que sus datos de carácter personal, recogidos de fuentes accesibles al
> público o datos que usted nos ha facilitado previamente, proceden de
> bases de datos propiedad de Advanced Software Production Line, S.L.
> (ASPL). No obstante, usted puede ejercitar sus derechos de acceso,
> rectificación, cancelación y oposición dispuestos en la mencionada Ley
> Orgánica, notificándolo por escrito a:
> ASPL - Protección Datos, C/Antonio Suárez 10 A-102, 28802, Alcalá de
> Henares (Madrid).
>
More information about the Axl
mailing list