Closed Bug 119391 Opened 23 years ago Closed 23 years ago

nsBaseWidget::GetRenderingContext() does not correctly check for errors

Categories

(Core :: XUL, defect)

defect
Not set
critical

Tracking

()

RESOLVED FIXED
mozilla0.9.8

People

(Reporter: roland.mainz, Assigned: roland.mainz)

Details

(Keywords: crash)

Attachments

(1 file, 1 obsolete file)

nsBaseWidget::GetRenderingContext() is a pain, it does not correctly check for
errors, causing crashes in some places (no details, just look at the source of
nsBaseWidget::GetRenderingContext() ... =:-)
Taking ...
Assignee: jaggernaut → Roland.Mainz
Severity: normal → critical
Keywords: crash
Target Milestone: --- → mozilla0.9.8
Status: NEW → ASSIGNED
Attached patch Patch for 2002-01-07-08-trunk (obsolete) — Splinter Review
Who wants to r=/sr= this cleanup ?
Keywords: patch, review
Comment on attachment 64444 [details] [diff] [review]
Patch for 2002-01-07-08-trunk

sr=sfraser
Attachment #64444 - Flags: superreview+
Comment on attachment 64444 [details] [diff] [review]
Patch for 2002-01-07-08-trunk

fix the else after return

and i'm not certain about addrefing the context...
I fixed the missing brackes around the |else| and added a comment why I am
addref'ing the object before we returning it (otherwise the nsCOMPtr would
destroy the nsIRenderingContext object and the function would return a ref to a
dead object) ...
Attachment #64444 - Attachment is obsolete: true
Is there any reason you have to keep indenting?  I'd much rather see this
written as:

nsIRenderingContext *rc;
nsresult rv = CallCreateInstance(kRenderingContextCID, &rc);
if (NS_FAILED(rv))
  return nsnull;

rv = rc->Init(mContext, this);
if (NS_FAILED(rv)) {
  NS_RELEASE(rc);
  return nsnull;
}

return rc;

which is shorter, less indented (and the *normal* code path is never indented),
and doesn't clutter things up with NS_WARNINGs for things that are never going
to happen.
Of course, if you wanted to make some more useful changes, you could change it
(and the callers) so it doesn't return an AddRef'd pointer.
dbaron:
Valid arguments... problem: The patch was checked in 30mins ago... ;-(

Dou you want this issue fixed (well, the original issue of this bug was to get
rid of the silly crash) or can I put this to my
check-for-such-coding-stlyes-in-the-next-patch list ?
Marking FIXED for now...
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: