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()
|
187 | 187 | |
188 | 188 | BBuffer::BBuffer(const buffer_clone_info& info) |
189 | 189 | : |
190 | | // must all be NULL/0 if not correctly initialized |
191 | 190 | fBufferList(NULL), |
| 191 | fArea(-1), |
192 | 192 | fData(NULL), |
193 | 193 | fSize(0) |
194 | 194 | { |
195 | 195 | CALLED(); |
196 | 196 | |
197 | | fMediaHeader.buffer = 0; |
198 | | // must be 0 if not registered |
| 197 | // Must be -1 if not registered |
| 198 | fMediaHeader.buffer = -1; |
199 | 199 | |
200 | 200 | // special case for BSmallBuffer |
201 | 201 | if (info.area == 0 && info.buffer == 0) |
… |
… |
BBuffer::BBuffer(const buffer_clone_info& info)
|
232 | 232 | ASSERT(reply.info.area > 0); |
233 | 233 | ASSERT(reply.info.size > 0); |
234 | 234 | |
| 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 | |
235 | 247 | // the response from media server contains enough information |
236 | 248 | // to clone the memory for this buffer |
237 | 249 | fSize = reply.info.size; |
… |
… |
BBuffer::BBuffer(const buffer_clone_info& info)
|
239 | 251 | fOffset = reply.info.offset; |
240 | 252 | fMediaHeader.size_used = 0; |
241 | 253 | 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 | | |
252 | 254 | fData = (char*)fData + fOffset; |
253 | 255 | } |
254 | 256 | |