Fenris
2004.07.03, 09:59 AM
Hi guys!
Out from the mine of legacy memory handling... I have a code snippet that takes a pure memory buffer (the contents of a QuickTime movie file) and loads it as a QuickTime movie. In essence, I use this to be able to run MP3:s out of a file archive.
Movie bmLoader::CreateMovieFromByteStream (const char *fileName, char *bytes, ByteCount size)
{
Handle bufferHandle, dataHandleRef;
OSErr err;
StringPtr name;
Movie theMovie;
Str255 pascName;
// Create a Pascal StringPtr from the C string
strcpy ((char *)(&pascName[1]), fileName);
pascName[0] = strlen (fileName);
name = pascName;
// Make bytes into a handle
err = PtrToHand (bytes, &bufferHandle, size);
// Create a handle to the buffer handle
err = PtrToHand(&bufferHandle, &dataHandleRef, sizeof(Handle));
// Concatenate the file name onto the data ref handle
err = PtrAndHand(name, dataHandleRef, name[0]+1);
err = NewMovieFromDataRef(&theMovie, 0, NULL, dataHandleRef, HandleDataHandlerSubType);
DisposeHandle (dataHandleRef);
return theMovie;
}
Now, MallocDebug tells me that PtrAndHand leaks an allocation the size of "ByteCount size" - that is, the entire size of the allocation in *bytes is lost. I can't see what I'm doing wrong here - is it obvious to anyone else? :(
Out from the mine of legacy memory handling... I have a code snippet that takes a pure memory buffer (the contents of a QuickTime movie file) and loads it as a QuickTime movie. In essence, I use this to be able to run MP3:s out of a file archive.
Movie bmLoader::CreateMovieFromByteStream (const char *fileName, char *bytes, ByteCount size)
{
Handle bufferHandle, dataHandleRef;
OSErr err;
StringPtr name;
Movie theMovie;
Str255 pascName;
// Create a Pascal StringPtr from the C string
strcpy ((char *)(&pascName[1]), fileName);
pascName[0] = strlen (fileName);
name = pascName;
// Make bytes into a handle
err = PtrToHand (bytes, &bufferHandle, size);
// Create a handle to the buffer handle
err = PtrToHand(&bufferHandle, &dataHandleRef, sizeof(Handle));
// Concatenate the file name onto the data ref handle
err = PtrAndHand(name, dataHandleRef, name[0]+1);
err = NewMovieFromDataRef(&theMovie, 0, NULL, dataHandleRef, HandleDataHandlerSubType);
DisposeHandle (dataHandleRef);
return theMovie;
}
Now, MallocDebug tells me that PtrAndHand leaks an allocation the size of "ByteCount size" - that is, the entire size of the allocation in *bytes is lost. I can't see what I'm doing wrong here - is it obvious to anyone else? :(