Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 046f61c

Browse files
committed
parser: Reenable ctxt->directory
Unused internally, but used in downstream code. Should fix #753.
1 parent 3c85a0e commit 046f61c

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

HTMLparser.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6185,6 +6185,12 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt)
61856185
ctxt->extSubURI = NULL;
61866186
DICT_FREE(ctxt->extSubSystem);
61876187
ctxt->extSubSystem = NULL;
6188+
6189+
if (ctxt->directory != NULL) {
6190+
xmlFree(ctxt->directory);
6191+
ctxt->directory = NULL;
6192+
}
6193+
61886194
if (ctxt->myDoc != NULL)
61896195
xmlFreeDoc(ctxt->myDoc);
61906196
ctxt->myDoc = NULL;

parser.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,11 @@ xmlCtxtGrowAttrs(xmlParserCtxtPtr ctxt, int nr) {
19401940
int
19411941
inputPush(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;

parserInternals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
24692469
if (ctxt->sax != NULL)
24702470
#endif /* LIBXML_SAX1_ENABLED */
24712471
xmlFree(ctxt->sax);
2472+
if (ctxt->directory != NULL) xmlFree(ctxt->directory);
24722473
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
24732474
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
24742475
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);

0 commit comments

Comments
 (0)