Closed Bug 235643 Opened 22 years ago Closed 21 years ago

all _CreatePrintSettings leak on failure

Categories

(Core :: Printing: Output, defect)

defect
Not set
normal

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
Blocks: 297277
Attached patch clean up on fail (obsolete) — Splinter Review
Assignee: printing → baafie
Status: NEW → ASSIGNED
Attachment #185850 - Flags: superreview?(bzbarsky)
Attachment #185850 - Flags: review?(timeless)
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.
Attached patch remove QI, use addref (obsolete) — Splinter Review
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
Attachment #185850 - Flags: superreview?(bzbarsky)
Attachment #185850 - Flags: review?(timeless)
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.
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);
Attached patch address comments (obsolete) — Splinter Review
Attachment #185855 - Attachment is obsolete: true
Attachment #185858 - Flags: superreview?(bzbarsky)
Attachment #185858 - Flags: review?(timeless)
Attachment #185855 - Flags: superreview?(bzbarsky)
Attachment #185855 - Flags: review?(timeless)
Attachment #185858 - Flags: review?(timeless) → review+
Attachment #185858 - Flags: superreview?(bzbarsky) → superreview+
Attachment #185858 - Flags: approval1.8b3?
Attachment #185858 - Flags: approval1.8b3? → approval1.8b3+
Attached patch same, for Mac and Windows (obsolete) — Splinter Review
This patches the remaining two _CreatePrintSettings() implementations.
Attachment #185901 - Flags: superreview?(bzbarsky)
Attachment #185901 - Flags: review?(timeless)
Attached patch remove cvs noise (obsolete) — Splinter Review
The right patch this time.
Attachment #185901 - Attachment is obsolete: true
Attachment #185902 - Flags: superreview?(bzbarsky)
Attachment #185902 - Flags: review?(timeless)
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 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.
Attached patch address comments (obsolete) — Splinter Review
Attachment #185902 - Attachment is obsolete: true
Attachment #186020 - Flags: superreview?(bzbarsky)
Attachment #186020 - Flags: review?(timeless)
Attachment #185902 - Flags: superreview?(bzbarsky)
Attachment #185902 - Flags: review?(timeless)
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+
Attached patch patch for checkin (obsolete) — Splinter Review
Attached patch patch for checkin (obsolete) — Splinter Review
removed some unintended whitespace messing about.
Attachment #186039 - Attachment is obsolete: true
Attachment #186020 - Flags: approval1.8b3?
Attachment #186020 - Flags: review?(timeless) → review+
Attached patch final patch (obsolete) — Splinter Review
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.
Attachment #186020 - Attachment is obsolete: true
Attachment #186040 - Attachment is obsolete: true
Attachment #186051 - Flags: review?(timeless)
Attachment #186051 - Flags: approval1.8b3?
Attachment #186020 - Flags: approval1.8b3?
Attachment #186051 - Flags: approval1.8b3?
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?
Attachment #186051 - Flags: approval1.8b3? → approval1.8b3+
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
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.

Attachment

General

Created:
Updated:
Size: