Skip to content

Commit

Permalink
tidy: Remove extraneous 'if' checks before calling delete. (libmythtv)
Browse files Browse the repository at this point in the history
According to the c++ reference, deleting a null pointer has no effect,
so non-null checks are unnecessary.

https://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html
  • Loading branch information
linuxdude42 committed Nov 23, 2019
1 parent bec6a23 commit 7e523ef
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 48 deletions.
3 changes: 1 addition & 2 deletions mythplugins/mythmusic/mythmusic/decoder.h
Expand Up @@ -35,8 +35,7 @@ class DecoderEvent : public MythEvent

~DecoderEvent()
{
if (m_error_msg)
delete m_error_msg;
delete m_error_msg;
}

const QString *errorMessage() const { return m_error_msg; }
Expand Down
10 changes: 3 additions & 7 deletions mythplugins/mythmusic/mythmusic/remoteavformatcontext.h
Expand Up @@ -42,8 +42,7 @@ class RemoteAVFormatContext
avformat_free_context(m_inputFC);
m_inputFC = avformat_alloc_context();

if (m_rf)
delete m_rf;
delete m_rf;

m_inputIsRemote = filename.startsWith("myth://");
if (m_inputIsRemote)
Expand Down Expand Up @@ -122,11 +121,8 @@ class RemoteAVFormatContext
m_inputFC = nullptr;
}

if (m_rf)
{
delete m_rf;
m_rf = nullptr;
}
delete m_rf;
m_rf = nullptr;

m_isOpen = false;
}
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/cc608reader.h
Expand Up @@ -43,8 +43,7 @@ class CC608Buffer
for (; i != buffers.end(); ++i)
{
CC608Text *cc = (*i);
if (cc)
delete cc;
delete cc;
}
buffers.clear();
lock.unlock();
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/mheg/dsmccreceiver.h
Expand Up @@ -13,8 +13,7 @@ class DsmccDii
DsmccDii() = default;
~DsmccDii()
{
if (m_modules)
delete[] m_modules;
delete[] m_modules;
}

unsigned long m_download_id {0};
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythtv/mpeg/mpegstreamdata.h
Expand Up @@ -387,15 +387,13 @@ class MTV_PUBLIC MPEGStreamData : public EITSource

inline void MPEGStreamData::SetPATSingleProgram(ProgramAssociationTable* pat)
{
if (_pat_single_program)
delete _pat_single_program;
delete _pat_single_program;
_pat_single_program = pat;
}

inline void MPEGStreamData::SetPMTSingleProgram(ProgramMapTable* pmt)
{
if (_pmt_single_program)
delete _pmt_single_program;
delete _pmt_single_program;
_pmt_single_program = pmt;
}

Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythtv/opengl/mythvideooutopengl.cpp
Expand Up @@ -179,8 +179,7 @@ MythVideoOutputOpenGL::~MythVideoOutputOpenGL()
m_openGLVideoPiPsReady.clear();
if (m_openGLPainter)
m_openGLPainter->SetSwapControl(true);
if (m_openGLVideo)
delete m_openGLVideo;
delete m_openGLVideo;
if (m_render)
{
m_render->makeCurrent();
Expand Down
12 changes: 4 additions & 8 deletions mythtv/libs/libmythtv/opengl/mythvideotexture.cpp
Expand Up @@ -20,14 +20,10 @@ void MythVideoTexture::DeleteTexture(MythRenderOpenGL *Context, MythVideoTexture
return;

OpenGLLocker locker(Context);
if (Texture->m_copyContext)
delete Texture->m_copyContext;
if (Texture->m_texture)
delete Texture->m_texture;
if (Texture->m_data)
delete [] Texture->m_data;
if (Texture->m_vbo)
delete Texture->m_vbo;
delete Texture->m_copyContext;
delete Texture->m_texture;
delete [] Texture->m_data;
delete Texture->m_vbo;

delete Texture;
}
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythtv/visualisations/videovisualdefs.h
Expand Up @@ -14,8 +14,7 @@ class LogScale

~LogScale()
{
if (indices)
delete [] indices;
delete [] indices;
}

int scale() const { return s; }
Expand All @@ -29,8 +28,7 @@ class LogScale
s = maxscale;
r = maxrange;

if (indices)
delete [] indices;
delete [] indices;

double alpha;
long double domain = (long double) maxscale;
Expand Down
15 changes: 5 additions & 10 deletions mythtv/libs/libmythui/opengl/mythrenderopengl.cpp
Expand Up @@ -700,12 +700,9 @@ void MythRenderOpenGL::DeleteTexture(MythGLTexture *Texture)

makeCurrent();
// N.B. Don't delete m_textureId - it is owned externally
if (Texture->m_texture)
delete Texture->m_texture;
if (Texture->m_data)
delete [] Texture->m_data;
if (Texture->m_vbo)
delete Texture->m_vbo;
delete Texture->m_texture;
delete [] Texture->m_data;
delete Texture->m_vbo;
delete Texture;
Flush();
doneCurrent();
Expand Down Expand Up @@ -1227,8 +1224,7 @@ void MythRenderOpenGL::ReleaseResources(void)
}
if (VERBOSE_LEVEL_CHECK(VB_GPU, LOG_INFO))
logDebugMarker("RENDER_RELEASE_END");
if (m_openglDebugger)
delete m_openglDebugger;
delete m_openglDebugger;
m_openglDebugger = nullptr;
Flush();

Expand Down Expand Up @@ -1524,8 +1520,7 @@ QOpenGLShaderProgram *MythRenderOpenGL::CreateShaderProgram(const QString &Verte
void MythRenderOpenGL::DeleteShaderProgram(QOpenGLShaderProgram *Program)
{
makeCurrent();
if (Program)
delete Program;
delete Program;
m_cachedMatrixUniforms.clear();
m_activeProgram = nullptr;
m_cachedUniformLocations.remove(Program);
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythupnp/upnpdevice.h
Expand Up @@ -217,8 +217,7 @@ class UPNP_PUBLIC DeviceLocation : public ReferenceCounter
// Should be atomic decrement
g_nAllocated--;

if (m_pDeviceDesc != nullptr)
delete m_pDeviceDesc;
delete m_pDeviceDesc;
}

UPnpDeviceDesc *m_pDeviceDesc; // We take ownership of this pointer.
Expand Down
7 changes: 2 additions & 5 deletions mythtv/libs/libmythupnp/upnputil.h
Expand Up @@ -117,11 +117,8 @@ inline NameValue& NameValue::operator=(const NameValue &nv)

inline NameValue::~NameValue()
{
if (m_pAttributes)
{
delete m_pAttributes;
m_pAttributes = nullptr;
}
delete m_pAttributes;
m_pAttributes = nullptr;
}

inline void NameValue::AddAttribute(const QString &name, const QString &value,
Expand Down

0 comments on commit 7e523ef

Please sign in to comment.