@@ -1940,8 +1940,11 @@ xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) {
19401940int
19411941inputPush (xmlParserCtxtPtr ctxt , xmlParserInputPtr value )
19421942{
1943+ char * directory = NULL ;
1944+
19431945 if ((ctxt == NULL ) || (value == NULL ))
19441946 return (-1 );
1947+
19451948 if (ctxt -> inputNr >= ctxt -> inputMax ) {
19461949 size_t newSize = ctxt -> inputMax * 2 ;
19471950 xmlParserInputPtr * tmp ;
@@ -1955,9 +1958,24 @@ inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
19551958 ctxt -> inputTab = tmp ;
19561959 ctxt -> inputMax = newSize ;
19571960 }
1961+
1962+ if ((ctxt -> inputNr == 0 ) && (value -> filename != NULL )) {
1963+ directory = xmlParserGetDirectory (value -> filename );
1964+ if (directory == NULL ) {
1965+ xmlErrMemory (ctxt );
1966+ return (-1 );
1967+ }
1968+ }
1969+
19581970 ctxt -> inputTab [ctxt -> inputNr ] = value ;
19591971 ctxt -> input = value ;
1960- return (ctxt -> inputNr ++ );
1972+
1973+ if (ctxt -> inputNr == 0 ) {
1974+ xmlFree (ctxt -> directory );
1975+ ctxt -> directory = directory ;
1976+ }
1977+
1978+ return (ctxt -> inputNr ++ );
19611979}
19621980/**
19631981 * inputPop:
@@ -13269,6 +13287,12 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt)
1326913287 ctxt -> extSubURI = NULL ;
1327013288 DICT_FREE (ctxt -> extSubSystem );
1327113289 ctxt -> extSubSystem = NULL ;
13290+
13291+ if (ctxt -> directory != NULL ) {
13292+ xmlFree (ctxt -> directory );
13293+ ctxt -> directory = NULL ;
13294+ }
13295+
1327213296 if (ctxt -> myDoc != NULL )
1327313297 xmlFreeDoc (ctxt -> myDoc );
1327413298 ctxt -> myDoc = NULL ;
0 commit comments