mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-22 17:17:35 +08:00
cdev: Fix deallocating devname in nuttx protected/kernel builds
The CDevs always live in kernel side. In kernel the devname is allocated in kernel heap. Replace "free" with kmm_free on nuttx to correct the deallocation; this automatically maps to "free" on flat build. Define __KERNEL__ flag so that the proper nuttx headers are used for building. TODO: It is fishy in the first place that the devname is allocated in inherited classes but deleted in the CDev base class. Especially when the devname is often passed as a constant string (which cannot even be freed) by many drivers. The allocation and deallocation of devname should be done within the CDev base class instead. Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
This commit is contained in:
@@ -43,6 +43,10 @@
|
||||
|
||||
#include <px4_platform_common/posix.h>
|
||||
|
||||
#if defined(__PX4_NUTTX)
|
||||
#include <nuttx/mm/mm.h>
|
||||
#endif
|
||||
|
||||
namespace cdev
|
||||
{
|
||||
|
||||
@@ -386,7 +390,11 @@ int CDev::unregister_driver_and_memory()
|
||||
}
|
||||
|
||||
if (_devname != nullptr) {
|
||||
#if defined(__PX4_NUTTX) && !defined(CONFIG_BUILD_FLAT)
|
||||
kmm_free((void *)_devname);
|
||||
#else
|
||||
free((void *)_devname);
|
||||
#endif
|
||||
_devname = nullptr;
|
||||
|
||||
} else {
|
||||
|
||||
@@ -49,7 +49,7 @@ px4_add_library(cdev
|
||||
CDev.hpp
|
||||
${SRCS_PLATFORM}
|
||||
)
|
||||
target_compile_options(cdev PRIVATE ${MAX_CUSTOM_OPT_LEVEL})
|
||||
target_compile_options(cdev PRIVATE ${MAX_CUSTOM_OPT_LEVEL} -D__KERNEL__)
|
||||
|
||||
if(PX4_TESTING)
|
||||
add_subdirectory(test)
|
||||
|
||||
Reference in New Issue
Block a user