From 6a1b7bfd2d52823d87aacb050c1d53f942aa8244 Mon Sep 17 00:00:00 2001 From: Mike Oliphant Date: Tue, 11 Apr 2023 08:26:40 -0700 Subject: [PATCH] Additional checks for LV2 mapPath and freePath supprt --- src/nam_plugin.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/nam_plugin.cpp b/src/nam_plugin.cpp index 61af652..134eb5e 100644 --- a/src/nam_plugin.cpp +++ b/src/nam_plugin.cpp @@ -213,6 +213,13 @@ namespace NAM { LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath); + if (map_path == nullptr) + { + lv2_log_error(&nam->logger, "LV2_STATE__mapPath unsupported by host\n"); + + return LV2_STATE_ERR_NO_FEATURE; + } + // Map absolute sample path to an abstract state path char* apath = map_path->abstract_path(map_path->handle, nam->currentModelPath.c_str()); @@ -221,7 +228,16 @@ namespace NAM { LV2_State_Free_Path* free_path = (LV2_State_Free_Path *)lv2_features_data(features, LV2_STATE__freePath); - free_path->free_path(free_path->handle, apath); + if (free_path != nullptr) + { + free_path->free_path(free_path->handle, apath); + } + else + { +#ifndef _WIN32 // Can't free library allocated memory on Windows + free(apath); +#endif + } return LV2_STATE_SUCCESS; } @@ -250,6 +266,14 @@ namespace NAM { } LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data(features, LV2_STATE__mapPath); + + if (map_path == nullptr) + { + lv2_log_error(&nam->logger, "LV2_STATE__mapPath unsupported by host\n"); + + return LV2_STATE_ERR_NO_FEATURE; + } + // Map abstract state path to absolute path char* path = map_path->absolute_path(map_path->handle, (const char *)value); @@ -274,7 +298,16 @@ namespace NAM { LV2_State_Free_Path* free_path = (LV2_State_Free_Path*)lv2_features_data(features, LV2_STATE__freePath); - free_path->free_path(free_path->handle, path); + if (free_path != nullptr) + { + free_path->free_path(free_path->handle, path); + } + else + { +#ifndef _WIN32 // Can't free library allocated memory on Windows + free(path); +#endif + } return result; }