Ticket #6188: 0001-BBuffer-Unregister-buffer-when-clone_area-fail-fixes.patch

File 0001-BBuffer-Unregister-buffer-when-clone_area-fail-fixes.patch, 2.1 KB (added by Barrett, 10 years ago)
  • src/kits/media/Buffer.cpp

    From 9616348aaea6c9bc55b409e03ae9040612886024 Mon Sep 17 00:00:00 2001
    From: Dario Casalinuovo <b.vitruvio@gmail.com>
    Date: Fri, 10 Apr 2015 19:47:04 +0200
    Subject: [PATCH 1/3] BBuffer: Unregister buffer when clone_area fail, fixes
     #6188.
    
    ---
     src/kits/media/Buffer.cpp | 28 +++++++++++++++-------------
     1 file changed, 15 insertions(+), 13 deletions(-)
    
    diff --git a/src/kits/media/Buffer.cpp b/src/kits/media/Buffer.cpp
    index abc6669..c942b26 100644
    a b BBuffer::Size()  
    187187
    188188BBuffer::BBuffer(const buffer_clone_info& info)
    189189    :
    190     // must all be NULL/0 if not correctly initialized
    191190    fBufferList(NULL),
     191    fArea(-1),
    192192    fData(NULL),
    193193    fSize(0)
    194194{
    195195    CALLED();
    196196
    197     fMediaHeader.buffer = 0;
    198         // must be 0 if not registered
     197    // Must be -1 if not registered
     198    fMediaHeader.buffer = -1;
    199199
    200200    // special case for BSmallBuffer
    201201    if (info.area == 0 && info.buffer == 0)
    BBuffer::BBuffer(const buffer_clone_info& info)  
    232232    ASSERT(reply.info.area > 0);
    233233    ASSERT(reply.info.size > 0);
    234234
     235    fArea = clone_area("a cloned BBuffer", &fData, B_ANY_ADDRESS,
     236        B_READ_AREA | B_WRITE_AREA, reply.info.area);
     237    if (fArea < 0) {
     238        ERROR("BBuffer::BBuffer: buffer cloning failed"
     239            ", unregistering buffer\n");
     240        server_unregister_buffer_command cmd;
     241        cmd.team = BPrivate::current_team();
     242        cmd.buffer_id = fMediaHeader.buffer;
     243        SendToServer(SERVER_UNREGISTER_BUFFER, &cmd, sizeof(cmd));
     244        return;
     245    }
     246
    235247    // the response from media server contains enough information
    236248    // to clone the memory for this buffer
    237249    fSize = reply.info.size;
    BBuffer::BBuffer(const buffer_clone_info& info)  
    239251    fOffset = reply.info.offset;
    240252    fMediaHeader.size_used = 0;
    241253    fMediaHeader.buffer = reply.info.buffer;
    242 
    243     fArea = clone_area("a cloned BBuffer", &fData, B_ANY_ADDRESS,
    244         B_READ_AREA | B_WRITE_AREA, reply.info.area);
    245     if (fArea < 0) {
    246         // TODO: should unregister buffer here
    247         ERROR("BBuffer::BBuffer: buffer cloning failed\n");
    248         fData = 0;
    249         return;
    250     }
    251 
    252254    fData = (char*)fData + fOffset;
    253255}
    254256