Bonjour tout le monde,
J'ai une erreur de segmentation que je ne comprend pas.
Voilà, j'ai une fonction suivante:
Lorsque j'appelle la fonction une première fois, je n'ai pas d'erreur et j'ai bien le resultat attendu. Mais, par contre, au second appel, j'ai droit à une erreur de segmentation. A l'aide de GDB, j'ai remarqué que cette erreur arrive après l'initialisation de XPath. Donc, pendant l'initialisation de contexte.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 gchar *getRef(xmlDocPtr doc, gint id){ xmlXPathContextPtr xmlperms_context = NULL; xmlXPathObjectPtr xmlobject; const char path_template[] = "/catalogue/article[%d]/ref/text()"; xmlChar *path; gchar *pRef; xmlXPathInit(); xmlperms_context = xmlXPathNewContext(doc); path = (xmlChar*)g_strdup_printf(path_template, id); xmlobject = xmlXPathEval(path, xmlperms_context); if(xmlobject->nodesetval){ pRef = g_strdup_printf("%s", (char *)xmlobject->nodesetval->nodeTab[0]->content); xmlFree(path); xmlXPathFreeObject(xmlobject); xmlXPathFreeContext(xmlperms_context); return pRef; } else{ xmlFree(path); xmlXPathFreeObject(xmlobject); xmlXPathFreeContext(xmlperms_context); return NULL; } }
Je ne comprend pas.
Merci d'avance.
Partager