From 9e55a3393018cdabb0a161943f2b191bb82a1ea0 Mon Sep 17 00:00:00 2001 From: Hao Yao Date: Wed, 28 Feb 2024 11:04:26 +0800 Subject: [PATCH] CameraShm: Add checking before using semaphore Signed-off-by: Hao Yao --- src/iutils/CameraShm.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/iutils/CameraShm.cpp b/src/iutils/CameraShm.cpp index 403402a8..f9b8b4a0 100644 --- a/src/iutils/CameraShm.cpp +++ b/src/iutils/CameraShm.cpp @@ -245,6 +245,9 @@ void CameraSharedMemory::openSemLock() { sem_close(mSemLock); sem_unlink(SEM_NAME); mSemLock = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0777, 1); + if (mSemLock == SEM_FAILED) { + LOGE("failed to re-open sem lock, errno: %s\n", strerror(errno)); + } } } @@ -255,9 +258,10 @@ void CameraSharedMemory::closeSemLock() { int CameraSharedMemory::lock() { int ret = OK; struct timespec ts; - CLEAR(ts); + CheckAndLogError(mSemLock == SEM_FAILED, VOID_VALUE, "invalid sem lock!"); // Wait the semaphore lock for 2 seconds + CLEAR(ts); clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += CAMERA_SHM_LOCK_TIME; while (((ret = sem_timedwait(mSemLock, &ts)) == -1) && errno == EINTR) {