Permalink
Browse files

fix some memory leaks

  • Loading branch information...
Léo Carnaut-Delord
Léo Carnaut-Delord committed Oct 5, 2018
1 parent 951de6d commit 228fa02bdadc623d894fd4a41dd15cf30d188473
@@ -52,6 +52,7 @@ class MODIO_DLL Instance
public:
Instance(u32 environment, u32 game_id, const std::string &api_key);
Instance(u32 environment, u32 game_id, const std::string &api_key, const std::string &root_path);
~Instance();
//General Methods
void process();
View
@@ -1,4 +1,5 @@
#include "ModioUtility.h"
#include "c\schemas\ModioInstalledMod.h"
namespace modio
{
@@ -78,6 +79,7 @@ void onGetAllEventsPoll(void *object, ModioResponse response, ModioEvent *events
reinstall = false;
modio::writeLogLine("Modfile changed event detected but you already have a newer version installed, the modfile will not be downloaded. Mod id: " + modio::toString(events_array[i].mod_id), MODIO_DEBUGLEVEL_LOG);
}
modioFreeInstalledMod(&installed_mod);
}
if (reinstall)
{
@@ -203,6 +205,7 @@ void pollEvents()
for (u32 i = 0; i < (u32)installed_mods_size; i++)
{
modioAddFilterInField(&filter, (char *)"mod_id", (char *)modio::toString(modio_installed_mods[i].mod_id).c_str());
modioFreeInstalledMod(&modio_installed_mods[i]);
}
modioGetAllEvents(NULL, filter, &onGetAllEventsPoll);
@@ -14,6 +14,11 @@ namespace modio
modioInit(environment, game_id, (char*)api_key.c_str(), (char*)root_path.c_str());
}
Instance::~Instance()
{
modioShutdown();
}
void Instance::setDebugLevel(u32 debug_level)
{
modioSetDebugLevel(debug_level);
@@ -91,5 +91,6 @@ namespace modio
FilterCreator::~FilterCreator()
{
modioFreeFilter(this->filter);
delete this->filter;
}
}
@@ -48,8 +48,8 @@ namespace modio
installed_mods.resize(installed_mods_size);
for (u32 i = 0; i<(u32)installed_mods_size; i++)
{
modio::InstalledMod installed_mod;
installed_mods[i].initialize(modio_installed_mods[i]);
modioFreeInstalledMod(&modio_installed_mods[i]);
}
delete[] modio_installed_mods;
@@ -117,23 +117,34 @@ u32 modioGetAllInstalledModsCount()
u32 modioGetModState(u32 mod_id)
{
u32 queue_size = modioGetModDownloadQueueCount();
u32 returnState = MODIO_MOD_NOT_INSTALLED;
ModioQueuedModDownload* download_queue = new ModioQueuedModDownload[queue_size];
modioGetModDownloadQueue(download_queue);
for(u32 i = 0; i<queue_size; i++)
for (u32 i = 0; i < queue_size; i++)
{
if(download_queue[i].mod_id == mod_id)
return download_queue[i].state;
returnState = download_queue[i].state;
modioFreeQueuedModDownload(&download_queue[i]);
}
delete[] download_queue;
if (returnState != MODIO_MOD_NOT_INSTALLED)
return returnState;
u32 installed_mods_size = modioGetAllInstalledModsCount();
ModioInstalledMod* installed_mods = new ModioInstalledMod[installed_mods_size];
modioGetAllInstalledMods(installed_mods);
for(u32 i = 0; i<installed_mods_size; i++)
for (u32 i = 0; i < installed_mods_size; i++)
{
if(installed_mods[i].mod_id == mod_id)
return MODIO_MOD_INSTALLED;
returnState = MODIO_MOD_INSTALLED;
modioFreeInstalledMod(&installed_mods[i]);
}
delete[] installed_mods;
return MODIO_MOD_NOT_INSTALLED;
return returnState;
}
}
@@ -34,6 +34,8 @@ extern "C"
{
if (installed_mod->path)
delete[] installed_mod->path;
modioFreeMod(&installed_mod->mod);
}
}
}
@@ -33,6 +33,7 @@ void shutdownCurl()
ongoing_downloads.clear();
delete current_download_handle;
curl_multi_cleanup(curl_multi_handle);
}
u32 getCallNumber()

0 comments on commit 228fa02

Please sign in to comment.