Aaron Schneider
2003-Aug-25 16:29 UTC
[vorbis-dev] mem leak when writing ogg vorbis comments
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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Michael Smith
2003-Aug-25 18:42 UTC
[vorbis-dev] mem leak when writing ogg vorbis comments
On Tuesday 26 August 2003 09:29, Aaron Schneider wrote:> 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.There's nothing really obviously wrong here, so... If the memory leak is inside vcedit.c, try updating to the cvs version - I'm not sure if that'll help, but it might. If it's elsewhere, perhaps you could tell us where it's happening? Your memory leak dump doesn't seem to say anything useful about where the leaked memory was allocated. Otherwise, a complete (but minimal) testcase we can actually compile and run would let us track this down (not win32-specific! It's horrid trying to read code that's full of that 'hungarian' notation). Mike --- >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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Is there a reason you allocate buf[] from the heap and delete it at exit, instead of just declaring it char buf[1024];? If you exit anywhere before the end, you'll leak. That's not what's causing your 256 byte leak, though. Other than that, the snipped part relating to pvcin might be interesting. Also, remember I have no idea what I'm talking about here. :-) -- Tom Felker, <tcfelker@mtco.com> <http://vlevel.sourceforge.net> - Stop fiddling with the volume knob. In order to understand recursion you must first understand recursion. --- >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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Aaron Schneider
2003-Aug-26 01:05 UTC
[vorbis-dev] RE: mem leak when writing ogg vorbis comments
> If the memory leak is inside vcedit.c, try updating to the cvs version - I'm > not sure if that'll help, but it might.That was it! We were compiling a very old version of vcedit.c into the program directly. I updated it and it worked just fine. Thanks for your suggestions and the quick responses. 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@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.