Fix double close.
This patch will fix the double close issue in SoundPool::doLoad():
status = MediaPlayer::decode(mFd, mOffset, mLength, &sampleRate, &numChannels, &format,
mHeap, &mSize);
ALOGV("close(%d)", mFd);
::close(mFd);
mFd = -1;
In MediaPlayerService::decode() which is called directly by
MediaPlayer::decode(), the fd will be closed, and after it return, the
mFd will be closed again.
When the system is idle, the second close will fail with EBADFD, but if
the system is busy, the mFd will be reused with another open/socket/pipe
system call, and the second close will cause errors.
Change-Id: If709515392cd490fea569658202524c51f8df785
Signed-off-by: Bao Haojun <baohaojun@gmail.com>
Signed-off-by: Wang Liang <wangliang@smartisan.cn>
diff --git a/media/libmedia/IMediaPlayerService.cpp b/media/libmedia/IMediaPlayerService.cpp
index 3c22b4c..011c6bb 100644
--- a/media/libmedia/IMediaPlayerService.cpp
+++ b/media/libmedia/IMediaPlayerService.cpp
@@ -250,6 +250,7 @@
size_t size;
status_t status = decode(fd, offset, length, &sampleRate, &numChannels, &format,
heap, &size);
+ ::close(fd);
reply->writeInt32(status);
if (status == NO_ERROR) {
reply->writeInt32(sampleRate);