Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RemoteFile leak fix and simplification
RemoteFile::Open() would leak file descriptors if Open() was explicitly
called again after passing a url to the contructor which itself called
Open().

This commit does several things:

- Moves Open() private since RemoteFile users shouldn't need to Open()
- Moves Close() private since there's no need to Close() if you can't Open().
  Close() is already called in the destructor.
- Convert the remaining uses of Open() to isOpen() since the connection is
  already opened in all these cases.
- Remove a few Close() uses since they were were redundant since we already
  Close() in the destructor.
- Removes unused SetURL() functionality.  If you can't Open() or Close(),
  then you need to pass the URL in to the constructor so there's no need.
- Fixes the actual leak in Open() by checking to see if the sockets are
  already open.  Just in case....  Closes #11341.

NOTE: This does modify the binary ABI version number due to the remotefile.h
      changes, so make clean, etc..
  • Loading branch information
cpinkham committed Jun 24, 2013
1 parent ba75244 commit 4c9dc6d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion mythplugins/mythmusic/mythmusic/decoderhandler.cpp
Expand Up @@ -756,7 +756,6 @@ MusicSGIODevice::MusicSGIODevice(const QString &url)

MusicSGIODevice::~MusicSGIODevice(void)
{
m_remotefile->Close();
delete m_remotefile;
}

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in ABI changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods in exported headers.
#define MYTH_BINARY_VERSION "0.27.20130609-2"
#define MYTH_BINARY_VERSION "0.27.20130624-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythbase/remotefile.cpp
Expand Up @@ -188,6 +188,9 @@ MythSocket *RemoteFile::openSocket(bool control)

bool RemoteFile::Open(void)
{
if (isOpen())
return true;

QMutexLocker locker(&lock);
controlSock = openSocket(true);
if (!controlSock)
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythbase/remotefile.h
Expand Up @@ -21,9 +21,7 @@ class MBASE_PUBLIC RemoteFile
const QStringList *possibleAuxiliaryFiles = NULL);
~RemoteFile();

bool Open();
bool ReOpen(QString newFilename);
void Close(void);

long long Seek(long long pos, int whence, long long curpos = -1);

Expand All @@ -39,7 +37,6 @@ class MBASE_PUBLIC RemoteFile

bool SaveAs(QByteArray &data);

void SetURL(const QString &url) { path = url; }
void SetTimeout(bool fast);

bool isOpen(void) const
Expand All @@ -51,6 +48,9 @@ class MBASE_PUBLIC RemoteFile
{ return auxfiles; }

private:
bool Open();
void Close(void);

MythSocket *openSocket(bool control);

QString path;
Expand Down
6 changes: 2 additions & 4 deletions mythtv/libs/libmythmetadata/metadatadownload.cpp
Expand Up @@ -363,7 +363,7 @@ MetadataLookupList MetadataDownload::readMXML(QString MXMLpath,
if (MXMLpath.startsWith("myth://"))
{
RemoteFile *rf = new RemoteFile(MXMLpath);
if (rf && rf->Open())
if (rf && rf->isOpen())
{
bool loaded = rf->SaveAs(mxmlraw);
if (loaded)
Expand All @@ -379,7 +379,6 @@ MetadataLookupList MetadataDownload::readMXML(QString MXMLpath,
LOG(VB_GENERAL, LOG_ERR,
QString("Corrupt or invalid MXML file."));
}
rf->Close();
}

delete rf;
Expand Down Expand Up @@ -428,7 +427,7 @@ MetadataLookupList MetadataDownload::readNFO(QString NFOpath,
if (NFOpath.startsWith("myth://"))
{
RemoteFile *rf = new RemoteFile(NFOpath);
if (rf && rf->Open())
if (rf && rf->isOpen())
{
bool loaded = rf->SaveAs(nforaw);
if (loaded)
Expand All @@ -443,7 +442,6 @@ MetadataLookupList MetadataDownload::readNFO(QString NFOpath,
LOG(VB_GENERAL, LOG_ERR,
QString("PIRATE ERROR: Invalid NFO file found."));
}
rf->Close();
}

delete rf;
Expand Down

0 comments on commit 4c9dc6d

Please sign in to comment.