fix mising close sem

This commit is contained in:
Joe Dong
2023-09-12 11:12:40 +08:00
parent 498bda9ac3
commit 405454a6b5
+19 -14
View File
@@ -1,18 +1,18 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023 Orbbec 3D Technology, Inc * Copyright (c) 2023 Orbbec 3D Technology, Inc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*******************************************************************************/ *******************************************************************************/
#include "orbbec_camera/ob_camera_node_driver.h" #include "orbbec_camera/ob_camera_node_driver.h"
#include <fcntl.h> #include <fcntl.h>
@@ -253,6 +253,11 @@ std::shared_ptr<ob::Device> OBCameraNodeDriver::selectDevice(
return list->getDevice(0); return list->getDevice(0);
} }
sem_t *device_sem = sem_open(DEFAULT_SEM_NAME.c_str(), O_CREAT, 0644, 1); sem_t *device_sem = sem_open(DEFAULT_SEM_NAME.c_str(), O_CREAT, 0644, 1);
std::shared_ptr<int> device_sem_guard(nullptr, [&, device_sem](int const *) {
if (device_sem != SEM_FAILED) {
sem_close(device_sem);
}
});
if (device_sem == SEM_FAILED) { if (device_sem == SEM_FAILED) {
RCLCPP_INFO_STREAM(logger_, "Failed to open semaphore"); RCLCPP_INFO_STREAM(logger_, "Failed to open semaphore");
return nullptr; return nullptr;