From b9c681df534fac4320ac9f8297956d20d5500df3 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 26 Jun 2020 22:16:06 +0100 Subject: [PATCH] Use state free-path in carla-lv2 whenever possible Signed-off-by: falkTX --- source/plugin/carla-lv2.cpp | 16 ++++++++++++++-- source/utils/CarlaLv2Utils.hpp | 10 ++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/source/plugin/carla-lv2.cpp b/source/plugin/carla-lv2.cpp index a58d1e19a..5039da81b 100644 --- a/source/plugin/carla-lv2.cpp +++ b/source/plugin/carla-lv2.cpp @@ -133,7 +133,13 @@ public: if (fLastProjectPath != nullptr) { - std::free(fLastProjectPath); + if (fFreePath != nullptr && fFreePath->free_path != nullptr) + fFreePath->free_path(fFreePath->handle, fLastProjectPath); +#ifndef CARLA_OS_WIN + // this is not safe to call under windows + else + std::free(fLastProjectPath); +#endif fLastProjectPath = nullptr; } } @@ -456,7 +462,13 @@ public: fLastProjectPath = nullptr; } - std::free(last); + if (fFreePath != nullptr && fFreePath->free_path != nullptr) + fFreePath->free_path(fFreePath->handle, last); +#ifndef CARLA_OS_WIN + // this is not safe to call under windows + else + std::free(last); +#endif } LV2_State_Status lv2_save(const LV2_State_Store_Function store, const LV2_State_Handle handle, diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index e37942583..e613f2550 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -1,6 +1,6 @@ /* * Carla LV2 utils - * Copyright (C) 2011-2019 Filipe Coelho + * Copyright (C) 2011-2020 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -570,6 +570,7 @@ public: fUsingNominal(false), fBufferSize(0), fSampleRate(sampleRate), + fFreePath(nullptr), fMakePath(nullptr), fUridMap(nullptr), fUridUnmap(nullptr), @@ -590,6 +591,7 @@ public: return; } + const LV2_State_Free_Path* freePath = nullptr; const LV2_State_Make_Path* makePath = nullptr; const LV2_Options_Option* options = nullptr; const LV2_URID_Map* uridMap = nullptr; @@ -598,7 +600,9 @@ public: for (int i=0; features[i] != nullptr; ++i) { - /**/ if (std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0) + /**/ if (std::strcmp(features[i]->URI, LV2_STATE__freePath) == 0) + freePath = (const LV2_State_Free_Path*)features[i]->data; + else if (std::strcmp(features[i]->URI, LV2_STATE__makePath) == 0) makePath = (const LV2_State_Make_Path*)features[i]->data; else if (std::strcmp(features[i]->URI, LV2_OPTIONS__options) == 0) options = (const LV2_Options_Option*)features[i]->data; @@ -667,6 +671,7 @@ public: fUridMap = uridMap; fURIs.map(uridMap); + fFreePath = freePath; fMakePath = makePath; fUridUnmap = uridUnmap; fWorker = worker; @@ -1183,6 +1188,7 @@ protected: double fSampleRate; // LV2 host features + const LV2_State_Free_Path* fFreePath; const LV2_State_Make_Path* fMakePath; const LV2_URID_Map* fUridMap; const LV2_URID_Unmap* fUridUnmap;