[vorbis-dev] mem leak when writing ogg vorbis comments

Aaron Schneider aaron at phatnoise.com
Mon Aug 25 16:29:49 PDT 2003



I'm working on a win32 C++/MFC program, and I'm having trouble getting rid of a memory leak when writing vorbis comments.  I've cut away everything except reading the file and then writing it out, and I still have a 256 byte mem leak (appended below).  The code was modeled after vorbiscomment.  It uses all the oggvorbis-win32sdk-1.0 static libs.  I tried checking the mailing list archives, but all the messages say is to copy vorbiscomment.

FYI, this software is used to put music on an Ogg-Vorbis enabled hardware project (PhatNoise PhatBox).  It also does ripping and Ogg-Vorbis encoding.  :)

Thanks!

Here's the code.  I tried to get rid of as much superfluous code as possible.
BOOL 
CHeaderInfoOGGBASIC::WriteFileTag(CString szFilePath)
{
        vcedit_state *state;
        vorbis_comment *pvcin;
        FILE * in=NULL, *out=NULL;
        char *buf=new char[1024];

        // Read the initial tag
        in = fopen(szFilePath, "rb");
        if (in == NULL) {
                // ... handle the failure case
                return FALSE;
        }

        state = vcedit_new_state();
        if(vcedit_open(state, in) < 0)	{
                // ... handle the failure case
                return FALSE;
        }

        // <removed all the stuff that fills the comment structure with the new values>

        // Write the file to another file in this directory.
        FindNextAvailableFileName(strTempFileInOldDir);
        out = fopen(strTempFileInOldDir, "wb");
        if(out == NULL){
                // ... handle the failure case
                return FALSE;
        }

        /* write out the modified stream */
        if(vcedit_write(state, out) < 0)	
        {
                // ... handle the failure case
                return FALSE;
        }	

        if (in) { fclose (in); in = NULL;}
        if (out) { fclose (out); out = NULL;	}

        vcedit_clear(state);
        state = NULL;

        // Try to rename the file to the old name
        if (rename(strTempFileInOldDir, szFilePath) != 0)
        {
                // ... handle the error case..
        }
    
        delete [] buf;
        return TRUE;
}

Here's the VS mem leak:
Dumping objects ->
{7713} normal block at 0x0FA6A990, 256 bytes long.
 Data: < vorbis    Xiph.> 03 76 6F 72 62 69 73 1D 00 00 00 58 69 70 68 2E 
Object dump complete.

Thanks,
Aaron

Aaron Schneider
Software Engineer
Phatnoise, Inc.
-------------------------------------------------------------------------

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list