Opened 12 years ago

Closed 12 years ago

#5000 closed defect (fixed)

null check of m_priv unnecessary in OpenGLContext dtor

Reported by: Erik Hovland <erik@…> Owned by: danielk
Priority: trivial Milestone: 0.22
Component: mythtv Version: head
Severity: low Keywords:
Cc: danielk@… Ticket locked: no


The dtor for OpenGLContext makes a check for null of m_priv. It turns out that m_priv is allocated in the ctor using new and never deleted or reallocated elsewhere in the class code. So there is no need to check for null that I can see. Which means the check is unnecessary. I should add that the check for m_priv comes after m_priv is dereferenced by MakeCurrent?(). So if the devs think the m_priv check is necessary after all, it should fall before MakeCurrent?() is called to avoid any segfaulting.

Attachments (1)

libs_libmythtv_openglcontext.cpp-remove-unneeded-null-check.patch (1.5 KB) - added by Erik Hovland <erik@…> 12 years ago.
removes m_priv null check in the dtor

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by Erik Hovland <erik@…>

removes m_priv null check in the dtor

comment:1 Changed 12 years ago by danielk

Milestone: unknown0.22
Owner: changed from Isaac Richards to danielk
Status: newassigned

Erik, I think the null pointer check is prudent, since if the new fails the class will hopefully be destructed soon afterward. But I see your point about MakeCurrent?(), I will fix this.

PS On Linux new always succeeds unless the default behavior has been changed by the user, but this is not the case on other operating systems, like some of the BSD's.

comment:2 Changed 12 years ago by Erik Hovland <erik@…>

Interesting. new is supposed to throw an exception bad_alloc, which is supposed to cause an abnormal exit of the program if there is no try/catch block. You're saying the C++ library in Linux doesn't do this?

comment:3 Changed 12 years ago by danielk

Not when you disable exceptions it doesn't :)

comment:4 Changed 12 years ago by danielk

Resolution: fixed
Status: assignedclosed

(In [16878]) Fixes #5000. Moves null pointer check up earlier in OpenGLContext dtor

Note: See TracTickets for help on using tickets.