mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-02-02 15:07:36 -05:00
Fixed memory leaks in custom xslt loader
This fixes some memory leaks in the xslt loader, additionally it now makes no copy of the URI if not needed.
This commit is contained in:
parent
0709b4e66d
commit
06545b25c0
18
src/xslt.c
18
src/xslt.c
@ -203,27 +203,31 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
|
|||||||
xsltLoadType type)
|
xsltLoadType type)
|
||||||
{
|
{
|
||||||
xmlDocPtr ret;
|
xmlDocPtr ret;
|
||||||
xmlChar *rel_path, *fn, *final_URI;
|
xmlChar *rel_path, *fn, *final_URI = NULL;
|
||||||
xsltStylesheet *c;
|
xsltStylesheet *c;
|
||||||
ice_config_t *config;
|
ice_config_t *config;
|
||||||
final_URI = xmlStrdup(URI);
|
|
||||||
struct stat file;
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
/* In case an include is loaded */
|
/* In case an include is loaded */
|
||||||
case XSLT_LOAD_STYLESHEET:
|
case XSLT_LOAD_STYLESHEET:
|
||||||
/* Not look in admindir if the include file exists */
|
/* Not look in admindir if the include file exists */
|
||||||
if (stat((char *)URI, &file) == 0)
|
if (access((char *)URI, F_OK) == 0)
|
||||||
break;
|
break;
|
||||||
c = (xsltStylesheet *) ctxt;
|
c = (xsltStylesheet *) ctxt;
|
||||||
/* Check if we actually have context/path */
|
/* Check if we actually have context/path */
|
||||||
if (ctxt == NULL || c->doc->URL == NULL)
|
if (ctxt == NULL || c->doc->URL == NULL)
|
||||||
break;
|
break;
|
||||||
|
/* Construct the right path */
|
||||||
rel_path = xmlBuildRelativeURI(URI, c->doc->URL);
|
rel_path = xmlBuildRelativeURI(URI, c->doc->URL);
|
||||||
if (rel_path != NULL && admin_path != NULL) {
|
if (rel_path != NULL && admin_path != NULL) {
|
||||||
fn = xmlBuildURI(rel_path, admin_path);
|
fn = xmlBuildURI(rel_path, admin_path);
|
||||||
if (fn != NULL && stat((char *)fn, &file) == 0) {
|
|
||||||
final_URI = fn;
|
final_URI = fn;
|
||||||
|
xmlFree(rel_path);
|
||||||
}
|
}
|
||||||
|
/* Fail if there was an error constructing the path */
|
||||||
|
if (final_URI == NULL) {
|
||||||
|
if (rel_path)
|
||||||
|
xmlFree(rel_path);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* In case a top stylesheet is loaded */
|
/* In case a top stylesheet is loaded */
|
||||||
@ -238,8 +242,12 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Get the actual xmlDoc */
|
/* Get the actual xmlDoc */
|
||||||
|
if (final_URI) {
|
||||||
ret = xslt_loader(final_URI, dict, options, ctxt, type);
|
ret = xslt_loader(final_URI, dict, options, ctxt, type);
|
||||||
xmlFree(final_URI);
|
xmlFree(final_URI);
|
||||||
|
} else {
|
||||||
|
ret = xslt_loader(URI, dict, options, ctxt, type);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user