Closed
Bug 1428860
Opened 6 years ago
Closed 5 years ago
XULDocument::GetElementsByAttributeNS may leak memory
Categories
(Core :: XUL, defect)
Core
XUL
Tracking
()
RESOLVED
FIXED
mozilla60
People
(Reporter: jeanluc.bonnafoux, Assigned: jeanluc.bonnafoux)
Details
Attachments
(1 file, 2 obsolete files)
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0 Build ID: 20180103231032 Steps to reproduce: Static C++ analysis of code (cppcheck) points out that XULDocument::GetElementsByAttributeNS may have a memory leak Actual results: This happens only if the call to RegisterNameSpace returns an error. in that case the local variable attrValue is not deleted accordingly Expected results: If RegisterNameSpace returns an error, attrValue should be deleted accordingly.
Comment hidden (mozreview-request) |
Comment 2•6 years ago
|
||
mozreview-review |
Comment on attachment 8941003 [details] Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory https://reviewboard.mozilla.org/r/211286/#review218114 ::: dom/xul/XULDocument.cpp:1250 (Diff revision 1) > nsresult rv = > nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI, > nameSpaceId); > if (NS_FAILED(rv)) { > aRv.Throw(rv); > + delete attrValue; Make attrValue a nsAutoPtr<nsString> (or UniquePtr<nsString>) instead, and .forget() where it's passed to the nsContentList constructor.
Attachment #8941003 -
Flags: review?(peterv) → review-
Comment hidden (mozreview-request) |
Comment 5•5 years ago
|
||
mozreview-review |
Comment on attachment 8941003 [details] Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory https://reviewboard.mozilla.org/r/211286/#review219692
Attachment #8941003 -
Flags: review?(peterv) → review+
Updated•5 years ago
|
Assignee: nobody → jeanluc.bonnafoux
Status: UNCONFIRMED → ASSIGNED
status-firefox58:
--- → wontfix
status-firefox59:
--- → fix-optional
Ever confirmed: true
Keywords: checkin-needed
Comment 6•5 years ago
|
||
Autoland can't push this until all pending issues in MozReview are marked as resolved.
Flags: needinfo?(jeanluc.bonnafoux)
Keywords: checkin-needed
Hello, I have amended the mozreview page accordingly. I hope it will be OK now. Thanks,
Flags: needinfo?(jeanluc.bonnafoux)
Keywords: checkin-needed
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/autoland/rev/721e8ff721d8 XULDocument::GetElementsByAttributeNS may leak memory r=peterv
Keywords: checkin-needed
Comment 9•5 years ago
|
||
Backed out for build bustages at /builds/worker/workspace/build/src/dom/xul/XULDocument.cpp Push that caused the failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=721e8ff721d8b0c81af2c91e3fb660a8cb0be058& Recent failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=157623513&repo=autoland&lineNumber=19133 Backout: https://hg.mozilla.org/integration/autoland/rev/d5c253aa5fb326756cc03ba2ae3d75226b0a1648
Flags: needinfo?(jeanluc.bonnafoux)
Assignee | ||
Comment 10•5 years ago
|
||
Hello, Thanks for the info, understood from logs this code does not compile with g++ whereas VC++ 2017 is ok. I am going to work on a new patch proposal that uses reinterpret_cast to instruct to compiler to convert to void* Thanks,
Flags: needinfo?(jeanluc.bonnafoux)
Comment hidden (mozreview-request) |
Assignee | ||
Comment 12•5 years ago
|
||
Hello, i have submitted a new fix proposal. Thanks,
Attachment #8941003 -
Flags: review+ → review?(peterv)
Assignee | ||
Comment 13•5 years ago
|
||
Hello, Could you please tell me if the new patch proposal has been submitted ok in mozreview? Thanks,
Comment 14•5 years ago
|
||
mozreview-review |
Comment on attachment 8941003 [details] Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory https://reviewboard.mozilla.org/r/211286/#review224774 ::: dom/xul/XULDocument.cpp:1119 (Diff revision 3) > already_AddRefed<nsINodeList> > XULDocument::GetElementsByAttribute(const nsAString& aAttribute, > const nsAString& aValue) > { > RefPtr<nsAtom> attrAtom(NS_Atomize(aAttribute)); > - void* attrValue = new nsString(aValue); > + nsAutoPtr<nsString> attrValue = new nsString(aValue); The compile error is on this line, you probably need to do nsAutoPtr<nsString> attrValue(new nsString(aValue)); ::: dom/xul/XULDocument.cpp:1123 (Diff revision 3) > RefPtr<nsAtom> attrAtom(NS_Atomize(aAttribute)); > - void* attrValue = new nsString(aValue); > + nsAutoPtr<nsString> attrValue = new nsString(aValue); > RefPtr<nsContentList> list = new nsContentList(this, > MatchAttribute, > nsContentUtils::DestroyMatchString, > - attrValue, > + reinterpret_cast<void*>(attrValue.forget()), Remove the reinterpret_cast.
Attachment #8941003 -
Flags: review?(peterv) → review-
Assignee | ||
Comment 15•5 years ago
|
||
Thanks for the review. Code without the reinterpret_cast failed to compile on Linux (Comment 9). This is why i have added this cast operation. I am going to amend object construction following your comment but i think the reinterpret_cast may be needed. Thanks,
Comment 16•5 years ago
|
||
(In reply to jbonnafo from comment #15) > Code without the reinterpret_cast failed to compile on Linux (Comment 9). > This is why i have added this cast operation. The error in the log is: /builds/worker/workspace/build/src/dom/xul/XULDocument.cpp:1149:37: error: conversion from 'nsString* {aka nsTString<char16_t>*}' to non-scalar type 'nsAutoPtr<nsTString<char16_t> >' requested nsAutoPtr<nsString> attrValue = new nsString(aValue); ^~~~~~~~~~~~~~~~~~~~
Comment hidden (mozreview-request) |
Attachment #8941003 -
Attachment is obsolete: true
Comment 18•5 years ago
|
||
mozreview-review |
Comment on attachment 8952843 [details] Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory https://reviewboard.mozilla.org/r/222068/#review228406
Attachment #8952843 -
Flags: review?(peterv) → review+
Keywords: checkin-needed
Comment 19•5 years ago
|
||
We're sorry, Autoland could not rebase your commits for you automatically. Please manually rebase your commits and try again. hg error in cmd: hg rebase -s d34220b17ede9078025bfa9a2c503efb3a7044f4 -d 3b82dc57cc73: rebasing 448640:d34220b17ede "Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory r=peterv" (tip) merging dom/xul/XULDocument.cpp warning: conflicts while merging dom/xul/XULDocument.cpp! (edit, then use 'hg resolve --mark') unresolved conflicts (see hg resolve, then hg rebase --continue)
Updated•5 years ago
|
Comment hidden (mozreview-request) |
Attachment #8952843 -
Attachment is obsolete: true
Comment 21•5 years ago
|
||
mozreview-review |
Comment on attachment 8953819 [details] Bug 1428860 - XULDocument::GetElementsByAttributeNS may leak memory https://reviewboard.mozilla.org/r/223004/#review229862
Attachment #8953819 -
Flags: review?(peterv) → review+
Keywords: checkin-needed
Comment 22•5 years ago
|
||
Pushed by ntim.bugs@gmail.com: https://hg.mozilla.org/integration/autoland/rev/7431e41b5d95 XULDocument::GetElementsByAttributeNS may leak memory r=peterv
Keywords: checkin-needed
Comment 23•5 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/7431e41b5d95
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
You need to log in
before you can comment on or make changes to this bug.
Description
•