Closed
Bug 235643
Opened 22 years ago
Closed 21 years ago
all _CreatePrintSettings leak on failure
Categories
(Core :: Printing: Output, defect)
Core
Printing: Output
Tracking
()
RESOLVED
FIXED
People
(Reporter: timeless, Assigned: bastiaan)
References
()
Details
(Keywords: memory-leak)
Attachments
(9 obsolete files)
66 nsPrintSettingsMac* printSettings = new nsPrintSettingsMac(); // does not
initially ref count
67 if (!printSettings)
68 return NS_ERROR_OUT_OF_MEMORY;
69 rv = printSettings->Init();
70 if (NS_FAILED(rv))
71 return rv;
printSettings is leaked when init fails. similar things happen in the other impls
| Assignee | ||
Comment 1•21 years ago
|
||
| Assignee | ||
Updated•21 years ago
|
Assignee: printing → baafie
Status: NEW → ASSIGNED
Attachment #185850 -
Flags: superreview?(bzbarsky)
Attachment #185850 -
Flags: review?(timeless)
Comment 2•21 years ago
|
||
Comment on attachment 185850 [details] [diff] [review]
clean up on fail
This code seems overly complicated. Why not just assign printSettings to
*_retval and then addref if it's not null?
In other words, I don't think this QI ever fails.
On a separate note, just 3 more lines of context would have made this patch
much much more readable. I suggest using -8 at least for diffs unless you have
good reason to use less context.
| Assignee | ||
Comment 3•21 years ago
|
||
Like so?
I've used more effective context for this patch. I'll keep in mind for future
ones, as well.
Attachment #185850 -
Attachment is obsolete: true
| Assignee | ||
Updated•21 years ago
|
Attachment #185850 -
Flags: superreview?(bzbarsky)
Attachment #185850 -
Flags: review?(timeless)
| Assignee | ||
Updated•21 years ago
|
Attachment #185855 -
Flags: superreview?(bzbarsky)
Attachment #185855 -
Flags: review?(timeless)
Comment on attachment 185855 [details] [diff] [review]
remove QI, use addref
> nsPrintSettings* printSettings = new nsPrintSettings(); // does not initially ref count
>+ *_retval = printSettings;
>+ if (!*_retval) return NS_ERROR_FAILURE;
NS_ERROR_OUT_OF_MEMORY, and personally i tend to check local variables.
Comment 5•21 years ago
|
||
I think the clearest and fastest code pattern here would be:
nsPrintSettings * printSettings = ...;
NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(*_retval = printSettings);
| Assignee | ||
Comment 6•21 years ago
|
||
| Assignee | ||
Updated•21 years ago
|
Attachment #185855 -
Attachment is obsolete: true
Attachment #185858 -
Flags: superreview?(bzbarsky)
Attachment #185858 -
Flags: review?(timeless)
| Assignee | ||
Updated•21 years ago
|
Attachment #185855 -
Flags: superreview?(bzbarsky)
Attachment #185855 -
Flags: review?(timeless)
Attachment #185858 -
Flags: review?(timeless) → review+
Updated•21 years ago
|
Attachment #185858 -
Flags: superreview?(bzbarsky) → superreview+
| Assignee | ||
Updated•21 years ago
|
Attachment #185858 -
Flags: approval1.8b3?
Updated•21 years ago
|
Attachment #185858 -
Flags: approval1.8b3? → approval1.8b3+
| Assignee | ||
Comment 7•21 years ago
|
||
This patches the remaining two _CreatePrintSettings() implementations.
Attachment #185901 -
Flags: superreview?(bzbarsky)
Attachment #185901 -
Flags: review?(timeless)
| Assignee | ||
Comment 8•21 years ago
|
||
The right patch this time.
Attachment #185901 -
Attachment is obsolete: true
Attachment #185902 -
Flags: superreview?(bzbarsky)
Attachment #185902 -
Flags: review?(timeless)
| Assignee | ||
Updated•21 years ago
|
Attachment #185901 -
Flags: superreview?(bzbarsky)
Attachment #185901 -
Flags: review?(timeless)
Comment on attachment 185858 [details] [diff] [review]
address comments
mozilla/gfx/src/nsPrintOptionsImpl.cpp 1.73
Attachment #185858 -
Attachment is obsolete: true
Comment 10•21 years ago
|
||
Comment on attachment 185902 [details] [diff] [review]
remove cvs noise
Generally, calling Init() on an object with a refcount of 0 is dangerous... I'd
suggest doing the NS_ADDREF before calling Init(), with an NS_RELEASE if Init()
fails.
| Assignee | ||
Comment 11•21 years ago
|
||
Attachment #185902 -
Attachment is obsolete: true
Attachment #186020 -
Flags: superreview?(bzbarsky)
Attachment #186020 -
Flags: review?(timeless)
| Assignee | ||
Updated•21 years ago
|
Attachment #185902 -
Flags: superreview?(bzbarsky)
Attachment #185902 -
Flags: review?(timeless)
Comment 12•21 years ago
|
||
Comment on attachment 186020 [details] [diff] [review]
address comments
Make that an NS_RELEASE(*_retval) so you're not setting the out param to a
known-bogus value, and sr=bzbarsky
Attachment #186020 -
Flags: superreview?(bzbarsky) → superreview+
| Assignee | ||
Comment 13•21 years ago
|
||
| Assignee | ||
Comment 14•21 years ago
|
||
removed some unintended whitespace messing about.
Attachment #186039 -
Attachment is obsolete: true
| Assignee | ||
Updated•21 years ago
|
Attachment #186020 -
Flags: approval1.8b3?
Attachment #186020 -
Flags: review?(timeless) → review+
| Assignee | ||
Comment 15•21 years ago
|
||
Both reviewers suggested that it is preferred to null out *_retval in case of
failure; thus, here is the hopefully final version of the patch which does just
that. sr=bzbarsky stands (which he conceded via email), assuming timeless
agrees.
| Assignee | ||
Updated•21 years ago
|
Attachment #186020 -
Attachment is obsolete: true
Attachment #186040 -
Attachment is obsolete: true
Attachment #186051 -
Flags: review?(timeless)
Attachment #186051 -
Flags: approval1.8b3?
| Assignee | ||
Updated•21 years ago
|
Attachment #186020 -
Flags: approval1.8b3?
Updated•21 years ago
|
Attachment #186051 -
Flags: approval1.8b3?
| Reporter | ||
Comment 16•21 years ago
|
||
Comment on attachment 186051 [details] [diff] [review]
final patch
r=me, marking sr=bz
Attachment #186051 -
Flags: superreview+
Attachment #186051 -
Flags: review?(timeless)
Attachment #186051 -
Flags: review+
Attachment #186051 -
Flags: approval1.8b3?
Updated•21 years ago
|
Attachment #186051 -
Flags: approval1.8b3? → approval1.8b3+
| Reporter | ||
Comment 17•21 years ago
|
||
Comment on attachment 186051 [details] [diff] [review]
final patch
mozilla/gfx/src/mac/nsPrintOptionsX.cpp 1.15
mozilla/gfx/src/windows/nsPrintOptionsWin.cpp 1.10
Attachment #186051 -
Attachment is obsolete: true
| Assignee | ||
Updated•21 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•