Ticket #11981: 0002-MediaFilePlayer-don-t-allocate-fName-in-the-heap-use.patch

File 0002-MediaFilePlayer-don-t-allocate-fName-in-the-heap-use.patch, 1.8 KB (added by Barrett, 10 years ago)
  • src/servers/media_addon/MediaFilePlayer.cpp

    From 99393bdfab67c889a3ecb0836a91e4fc268b634c Mon Sep 17 00:00:00 2001
    From: Dario Casalinuovo <b.vitruvio@gmail.com>
    Date: Thu, 2 Apr 2015 00:55:49 +0200
    Subject: [PATCH 2/2] MediaFilePlayer: don't allocate fName in the heap, use
     BString instead.
    
    ---
     src/servers/media_addon/MediaFilePlayer.cpp | 4 +---
     src/servers/media_addon/MediaFilePlayer.h   | 3 ++-
     2 files changed, 3 insertions(+), 4 deletions(-)
    
    diff --git a/src/servers/media_addon/MediaFilePlayer.cpp b/src/servers/media_addon/MediaFilePlayer.cpp
    index 9ce7818..0b997e2 100644
    a b PlayMediaFile(const char* media_type, const char* media_name)  
    6161MediaFilePlayer::MediaFilePlayer(const char* media_type,
    6262    const char* media_name, entry_ref* ref)
    6363    :
     64    fName(media_name),
    6465    fInitCheck(B_ERROR),
    6566    fRef(*ref),
    6667    fSoundPlayer(NULL),
    6768    fPlayTrack(NULL)
    6869{
    69     fName = strdup(media_name);
    70 
    7170    fPlayFile = new BMediaFile(&fRef);
    7271    fInitCheck = fPlayFile->InitCheck();
    7372    if (fInitCheck != B_OK)
    MediaFilePlayer::~MediaFilePlayer()  
    111110{
    112111    delete fSoundPlayer;
    113112    delete fPlayFile;
    114     free(fName);
    115113}
    116114
    117115
  • src/servers/media_addon/MediaFilePlayer.h

    diff --git a/src/servers/media_addon/MediaFilePlayer.h b/src/servers/media_addon/MediaFilePlayer.h
    index 508be95..5ef0bb5 100644
    a b  
    1111#include <MediaFile.h>
    1212#include <MediaTrack.h>
    1313#include <SoundPlayer.h>
     14#include <String.h>
    1415
    1516
    1617void PlayMediaFile(const char* media_type, const char* media_name);
    public:  
    3839                                const media_raw_audio_format& format);
    3940
    4041private:
    41     char*                   fName;
     42    BString                 fName;
    4243    status_t                fInitCheck;
    4344    entry_ref               fRef;
    4445    BSoundPlayer*           fSoundPlayer;