From 1b30f0ff11a3683a50fe172a49facecef3102694 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 27 Jun 2020 12:06:00 +0200 Subject: [PATCH] Allocate the handles on the heap instead of the stack --- source/PluginUtils.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/source/PluginUtils.cpp b/source/PluginUtils.cpp index 1b28621..ab9773b 100644 --- a/source/PluginUtils.cpp +++ b/source/PluginUtils.cpp @@ -16,9 +16,8 @@ ****************************************************************************/ #include + #include "wups_backend/PluginUtils.h" -#include "wups_backend/PluginMetaInformation.h" -#include "wups_backend/PluginContainer.h" #include "imports.h" std::optional PluginUtils::getMetaInformationForBuffer(char *buffer, size_t size) { @@ -90,26 +89,46 @@ std::optional PluginUtils::getPluginForBuffer(char *buffer, siz std::vector PluginUtils::getLoadedPlugins(uint32_t maxSize) { std::vector result; - plugin_container_handle handles[maxSize]; + plugin_container_handle *handles = (plugin_container_handle *) malloc(maxSize * sizeof(plugin_container_handle)); + if (!handles) { + return result; + } uint32_t realSize = 0; if (WUPSGetLoadedPlugins(handles, maxSize, &realSize) != 0) { + free(handles); // DEBUG_FUNCTION_LINE("Failed"); return result; } if (realSize == 0) { + free(handles); // DEBUG_FUNCTION_LINE("realsize is 0"); return result; } - plugin_data_handle dataHandles[realSize]; + plugin_data_handle *dataHandles = (plugin_container_handle *) malloc(realSize * sizeof(plugin_container_handle)); + if(!dataHandles){ + free(handles); + return result; + } + if (WUPSGetPluginDataForContainerHandles(handles, dataHandles, realSize) != 0) { + free(handles); + free(dataHandles); // DEBUG_FUNCTION_LINE("Failed to get plugin data"); return result; } - plugin_information information[realSize]; + plugin_information* information = (plugin_information *) malloc(realSize * sizeof(plugin_information)); + if(information == NULL){ + free(handles); + free(dataHandles); + return result; + } if (WUPSGetMetaInformation(handles, information, realSize) != 0) { + free(handles); + free(dataHandles); + free(information); // DEBUG_FUNCTION_LINE("Failed to get meta information for handles"); return result; } @@ -126,6 +145,10 @@ std::vector PluginUtils::getLoadedPlugins(uint32_t maxSize) { result.push_back(PluginContainer(pluginData, metaInfo, handles[i])); } + free(handles); + free(dataHandles); + free(information); + return result; }