@@ -854,6 +854,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
854854 value = PyBytes_FromString (map_p -> value );
855855 PyADD_DICT_VALUE (retdata , key , value );
856856 } else {
857+ xmlXPathFreeContext (xpctx );
858+ xmlFreeDoc (xpdoc );
859+ free (key );
857860 PyReturnError (PyExc_ValueError , "Could not get key value: %s [%i] (Defining key: %s)" ,
858861 map_p -> rootpath , elmtid , map_p -> key );
859862 }
@@ -918,6 +921,10 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
918921 PyADD_DICT_VALUE (retdata , key , value );
919922 xmlXPathFreeObject (xpo );
920923 } else {
924+ xmlXPathFreeObject (xpo );
925+ xmlXPathFreeContext (xpctx );
926+ xmlFreeDoc (xpdoc );
927+ free (key );
921928 PyReturnError (PyExc_ValueError , "Could not get key value: "
922929 "%s [%i] (Defining key: %s)" ,
923930 map_p -> rootpath , elmtid , map_p -> key );
@@ -931,6 +938,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
931938 break ;
932939 }
933940 if ( _get_key_value (logp , key , 256 , map_p , xpctx , 0 ) == NULL ) {
941+ xmlXPathFreeContext (xpctx );
942+ xmlFreeDoc (xpdoc );
943+ free (key );
934944 PyReturnError (PyExc_ValueError ,
935945 "Could not get key value: %s [%i] (Defining key: %s)" ,
936946 map_p -> rootpath , elmtid , map_p -> key );
@@ -945,6 +955,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
945955 break ;
946956 }
947957 if ( _get_key_value (logp , key , 256 , map_p , xpctx , 0 ) == NULL ) {
958+ xmlXPathFreeContext (xpctx );
959+ xmlFreeDoc (xpdoc );
960+ free (key );
948961 PyReturnError (PyExc_ValueError ,
949962 "Could not get key value: %s [%i] (Defining key: %s)" ,
950963 map_p -> rootpath , elmtid , map_p -> key );
@@ -956,6 +969,9 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
956969 if ( xpo != NULL ) {
957970 xmlXPathFreeObject (xpo );
958971 }
972+ xmlXPathFreeContext (xpctx );
973+ xmlFreeDoc (xpdoc );
974+ free (key );
959975 PyReturnError (PyExc_ValueError ,
960976 "Could not get key value: %s [%i] (Defining key: %s)" ,
961977 map_p -> rootpath , elmtid , map_p -> key );
@@ -991,6 +1007,10 @@ PyObject *_deep_pythonize(Log_t *logp, PyObject *retdata,
9911007 PyList_Append (value , dataset );
9921008 }
9931009 } else {
1010+ xmlXPathFreeObject (xpo );
1011+ xmlXPathFreeContext (xpctx );
1012+ xmlFreeDoc (xpdoc );
1013+ free (key );
9941014 // If NULL, something is wrong - exception is already set.
9951015 return NULL ;
9961016 }
@@ -1047,6 +1067,8 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10471067
10481068 xpctx = xmlXPathNewContext (xpdoc );
10491069 if ( xpctx == NULL ) {
1070+ xmlFreeDoc (xpdoc );
1071+ free (key );
10501072 PyReturnError (PyExc_MemoryError , "Could not setup new XPath context" );
10511073 }
10521074 xpctx -> node = data_n ;
@@ -1062,6 +1084,10 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10621084 if ( res == NULL ) {
10631085 // Exit if we get NULL - something is wrong
10641086 //and exception is set
1087+ xmlXPathFreeObject (xpo );
1088+ xmlXPathFreeContext (xpctx );
1089+ xmlFreeDoc (xpdoc );
1090+ free (key );
10651091 return NULL ;
10661092 }
10671093 }
@@ -1084,6 +1110,7 @@ PyObject *pythonizeXMLnode(Log_t *logp, ptzMAP *in_map, xmlNode *data_n) {
10841110 if ( res == NULL ) {
10851111 // Exit if we get NULL - something is wrong
10861112 //and exception is set
1113+ free (key );
10871114 return NULL ;
10881115 }
10891116 }
0 commit comments