[haiku-commits] Re: haiku: hrev44261 - in src: add-ons/media/plugins/ffmpeg apps/mediaplayer

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 25 Jun 2012 08:57:03 +0200

On 25.06.2012 02:55, stpere@xxxxxxxxx wrote:
diff --git a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp 
b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
index 9b3de2d..bb12197 100644
--- a/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
+++ b/src/add-ons/media/plugins/ffmpeg/AVFormatReader.cpp
[...]
@@ -1478,12 +1481,14 @@ AVFormatReader::~AVFormatReader()
  const char*
  AVFormatReader::Copyright()
  {
-// TODO: Could not find the equivalent in libavformat >= version 53.
-// Use metadata API instead!
-//     if (fStreams != NULL && fStreams[0] != NULL)
-//             return fStreams[0]->Context()->copyright;
-       // TODO: Return copyright of the file instead!
-       return "Copyright 2009, Stephan Aßmus";
+       BMessage* message = new BMessage();
+       if (GetMetaData(message) == B_OK) {
+               const char* copyright;
+               if (message->FindString("copyright", &copyright) == B_OK)
+                       return copyright;
+       }
+       delete message;
+       return "";
  }

This leaks the BMessage in the non-error case. Please just allocate the BMessage on the stack. That however will make it necessary to allocate the storage for the copyright string somewhere, I propose in a new BString member. Your version worked /because/ you leaked the message, otherwise the storage for the string would have been freed. Here my proposal for the code:

if (fCopyright.Length() <= 0) {
        BMessage message;
        if (GetMetaData(&message) == B_OK)
                message.FindString("copyright", &fCopyright);
}

return fCopyright.String();


Best regards,
-Stephan

Other related posts: