Commit 137a3652 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Release the returned lists from Gecko's QuerySelectorAll even on error.

Gecko may return a pseudo-element-list even on error (such as with an invalid selector, for example), which holds refs to elements and leaks. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com>
parent 88ec9150
...@@ -2685,7 +2685,7 @@ static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BST ...@@ -2685,7 +2685,7 @@ static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BST
IHTMLElementCollection **ppelColl) IHTMLElementCollection **ppelColl)
{ {
HTMLDocumentNode *This = impl_from_IHTMLDocument3(iface); HTMLDocumentNode *This = impl_from_IHTMLDocument3(iface);
nsIDOMNodeList *node_list; nsIDOMNodeList *node_list = NULL;
nsAString selector_str; nsAString selector_str;
WCHAR *selector; WCHAR *selector;
nsresult nsres; nsresult nsres;
...@@ -2715,6 +2715,8 @@ static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BST ...@@ -2715,6 +2715,8 @@ static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BST
free(selector); free(selector);
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
ERR("QuerySelectorAll failed: %08lx\n", nsres); ERR("QuerySelectorAll failed: %08lx\n", nsres);
if(node_list)
nsIDOMNodeList_Release(node_list);
return E_FAIL; return E_FAIL;
} }
...@@ -2781,12 +2783,15 @@ static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, ...@@ -2781,12 +2783,15 @@ static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface,
return E_UNEXPECTED; return E_UNEXPECTED;
} }
nslist = NULL;
nsAString_InitDepend(&nsstr, v); nsAString_InitDepend(&nsstr, v);
nsres = nsIDOMDocumentFragment_QuerySelectorAll(docfrag, &nsstr, &nslist); nsres = nsIDOMDocumentFragment_QuerySelectorAll(docfrag, &nsstr, &nslist);
nsAString_Finish(&nsstr); nsAString_Finish(&nsstr);
nsIDOMDocumentFragment_Release(docfrag); nsIDOMDocumentFragment_Release(docfrag);
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
ERR("QuerySelectorAll failed: %08lx\n", nsres); ERR("QuerySelectorAll failed: %08lx\n", nsres);
if(nslist)
nsIDOMNodeList_Release(nslist);
return E_FAIL; return E_FAIL;
} }
} }
...@@ -4751,7 +4756,7 @@ static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, B ...@@ -4751,7 +4756,7 @@ static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, B
static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel) static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel)
{ {
HTMLDocumentNode *This = impl_from_IDocumentSelector(iface); HTMLDocumentNode *This = impl_from_IDocumentSelector(iface);
nsIDOMNodeList *node_list; nsIDOMNodeList *node_list = NULL;
nsAString nsstr; nsAString nsstr;
nsresult nsres; nsresult nsres;
HRESULT hres; HRESULT hres;
...@@ -4773,6 +4778,8 @@ static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface ...@@ -4773,6 +4778,8 @@ static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
WARN("QuerySelectorAll failed: %08lx\n", nsres); WARN("QuerySelectorAll failed: %08lx\n", nsres);
if(node_list)
nsIDOMNodeList_Release(node_list);
return map_nsresult(nsres); return map_nsresult(nsres);
} }
...@@ -5946,7 +5953,7 @@ static HRESULT HTMLDocumentNode_next_dispid(DispatchEx *dispex, DISPID id, DISPI ...@@ -5946,7 +5953,7 @@ static HRESULT HTMLDocumentNode_next_dispid(DispatchEx *dispex, DISPID id, DISPI
{ {
DWORD idx = (id == DISPID_STARTENUM) ? 0 : id - MSHTML_DISPID_CUSTOM_MIN + 1; DWORD idx = (id == DISPID_STARTENUM) ? 0 : id - MSHTML_DISPID_CUSTOM_MIN + 1;
HTMLDocumentNode *This = impl_from_DispatchEx(dispex); HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
nsIDOMNodeList *node_list; nsIDOMNodeList *node_list = NULL;
const PRUnichar *name; const PRUnichar *name;
nsIDOMElement *nselem; nsIDOMElement *nselem;
nsIDOMNode *nsnode; nsIDOMNode *nsnode;
...@@ -5973,8 +5980,11 @@ static HRESULT HTMLDocumentNode_next_dispid(DispatchEx *dispex, DISPID id, DISPI ...@@ -5973,8 +5980,11 @@ static HRESULT HTMLDocumentNode_next_dispid(DispatchEx *dispex, DISPID id, DISPI
nsAString_InitDepend(&nsstr, L":-moz-any(applet,embed,form,iframe,img,object)[name]"); nsAString_InitDepend(&nsstr, L":-moz-any(applet,embed,form,iframe,img,object)[name]");
nsres = nsIDOMHTMLDocument_QuerySelectorAll(This->html_document, &nsstr, &node_list); nsres = nsIDOMHTMLDocument_QuerySelectorAll(This->html_document, &nsstr, &node_list);
nsAString_Finish(&nsstr); nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres)) {
if(node_list)
nsIDOMNodeList_Release(node_list);
return map_nsresult(nsres); return map_nsresult(nsres);
}
for(i = 0, hres = S_OK; SUCCEEDED(hres); i++) { for(i = 0, hres = S_OK; SUCCEEDED(hres); i++) {
nsres = nsIDOMNodeList_Item(node_list, i, &nsnode); nsres = nsIDOMNodeList_Item(node_list, i, &nsnode);
......
...@@ -6476,7 +6476,7 @@ static HRESULT WINAPI ElementSelector_querySelector(IElementSelector *iface, BST ...@@ -6476,7 +6476,7 @@ static HRESULT WINAPI ElementSelector_querySelector(IElementSelector *iface, BST
static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel) static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel)
{ {
HTMLElement *This = impl_from_IElementSelector(iface); HTMLElement *This = impl_from_IElementSelector(iface);
nsIDOMNodeList *node_list; nsIDOMNodeList *node_list = NULL;
nsAString nsstr; nsAString nsstr;
nsresult nsres; nsresult nsres;
HRESULT hres; HRESULT hres;
...@@ -6493,6 +6493,8 @@ static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface, ...@@ -6493,6 +6493,8 @@ static HRESULT WINAPI ElementSelector_querySelectorAll(IElementSelector *iface,
nsAString_Finish(&nsstr); nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
WARN("QuerySelectorAll failed: %08lx\n", nsres); WARN("QuerySelectorAll failed: %08lx\n", nsres);
if(node_list)
nsIDOMNodeList_Release(node_list);
return map_nsresult(nsres); return map_nsresult(nsres);
} }
......
...@@ -1605,9 +1605,9 @@ void bind_event_scripts(HTMLDocumentNode *doc) ...@@ -1605,9 +1605,9 @@ void bind_event_scripts(HTMLDocumentNode *doc)
{ {
HTMLPluginContainer *plugin_container; HTMLPluginContainer *plugin_container;
nsIDOMHTMLScriptElement *nsscript; nsIDOMHTMLScriptElement *nsscript;
nsIDOMNodeList *node_list = NULL;
HTMLScriptElement *script_elem; HTMLScriptElement *script_elem;
EventTarget *event_target; EventTarget *event_target;
nsIDOMNodeList *node_list;
nsIDOMNode *script_node; nsIDOMNode *script_node;
nsAString selector_str; nsAString selector_str;
IDispatch *event_disp; IDispatch *event_disp;
...@@ -1626,6 +1626,8 @@ void bind_event_scripts(HTMLDocumentNode *doc) ...@@ -1626,6 +1626,8 @@ void bind_event_scripts(HTMLDocumentNode *doc)
nsAString_Finish(&selector_str); nsAString_Finish(&selector_str);
if(NS_FAILED(nsres)) { if(NS_FAILED(nsres)) {
ERR("QuerySelectorAll failed: %08lx\n", nsres); ERR("QuerySelectorAll failed: %08lx\n", nsres);
if(node_list)
nsIDOMNodeList_Release(node_list);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment