mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-18 02:39:21 +01:00
Fix some memory leaks
This commit is contained in:
parent
c9a655eeee
commit
aec8fc5035
@ -76,25 +76,26 @@ void VirtualMountDevice(const char * path)
|
|||||||
|
|
||||||
void AddVirtualPath(const char *name, const char *alias, const char *prefix)
|
void AddVirtualPath(const char *name, const char *alias, const char *prefix)
|
||||||
{
|
{
|
||||||
if(!VIRTUAL_PARTITIONS)
|
if (!VIRTUAL_PARTITIONS) {
|
||||||
VIRTUAL_PARTITIONS = (VIRTUAL_PARTITION *) malloc(sizeof(VIRTUAL_PARTITION));
|
VIRTUAL_PARTITIONS = (VIRTUAL_PARTITION *) malloc(sizeof(VIRTUAL_PARTITION));
|
||||||
|
}
|
||||||
|
|
||||||
VIRTUAL_PARTITION * tmp = realloc(VIRTUAL_PARTITIONS, sizeof(VIRTUAL_PARTITION)*(MAX_VIRTUAL_PARTITIONS+1));
|
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_PARTITIONS, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_PARTITIONS + 1));
|
||||||
if(!tmp)
|
if (!tmp) {
|
||||||
{
|
free(VIRTUAL_PARTITIONS);
|
||||||
free(VIRTUAL_PARTITIONS);
|
VIRTUAL_PARTITIONS = NULL;
|
||||||
MAX_VIRTUAL_PARTITIONS = 0;
|
MAX_VIRTUAL_PARTITIONS = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIRTUAL_PARTITIONS = tmp;
|
VIRTUAL_PARTITIONS = tmp;
|
||||||
|
|
||||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].name = strdup(name);
|
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].name = strdup(name);
|
||||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].alias = strdup(alias);
|
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].alias = strdup(alias);
|
||||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].prefix = strdup(prefix);
|
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].prefix = strdup(prefix);
|
||||||
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].inserted = true;
|
VIRTUAL_PARTITIONS[MAX_VIRTUAL_PARTITIONS].inserted = true;
|
||||||
|
|
||||||
MAX_VIRTUAL_PARTITIONS++;
|
MAX_VIRTUAL_PARTITIONS++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +106,10 @@ void AddVirtualPath(const char *name, const char *alias, const char *prefix)
|
|||||||
|
|
||||||
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_FS, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_FS + 1));
|
VIRTUAL_PARTITION *tmp = realloc(VIRTUAL_FS, sizeof(VIRTUAL_PARTITION) * (MAX_VIRTUAL_FS + 1));
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
free(VIRTUAL_FS);
|
if (VIRTUAL_FS) {
|
||||||
|
free(VIRTUAL_FS);
|
||||||
|
VIRTUAL_FS = 0;
|
||||||
|
}
|
||||||
MAX_VIRTUAL_FS = 0;
|
MAX_VIRTUAL_FS = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -150,21 +154,45 @@ void MountVirtualDevices()
|
|||||||
VirtualMountDevice("usb:/");
|
VirtualMountDevice("usb:/");
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnmountVirtualPaths()
|
void UnmountVirtualPaths() {
|
||||||
{
|
uint32_t i = 0;
|
||||||
uint32_t i = 0;
|
for (i = 0; i < MAX_VIRTUAL_PARTITIONS; i++) {
|
||||||
for(i = 0; i < MAX_VIRTUAL_PARTITIONS; i++)
|
if (VIRTUAL_PARTITIONS[i].name) {
|
||||||
{
|
free(VIRTUAL_PARTITIONS[i].name);
|
||||||
if(VIRTUAL_PARTITIONS[i].name)
|
}
|
||||||
free(VIRTUAL_PARTITIONS[i].name);
|
if (VIRTUAL_PARTITIONS[i].alias) {
|
||||||
if(VIRTUAL_PARTITIONS[i].alias)
|
free(VIRTUAL_PARTITIONS[i].alias);
|
||||||
free(VIRTUAL_PARTITIONS[i].alias);
|
}
|
||||||
if(VIRTUAL_PARTITIONS[i].prefix)
|
if (VIRTUAL_PARTITIONS[i].prefix) {
|
||||||
free(VIRTUAL_PARTITIONS[i].prefix);
|
free(VIRTUAL_PARTITIONS[i].prefix);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(VIRTUAL_PARTITIONS)
|
for (i = 0; i < MAX_VIRTUAL_FS_VOL; i++) {
|
||||||
free(VIRTUAL_PARTITIONS);
|
if (VIRTUAL_FS_VOL[i].name) {
|
||||||
VIRTUAL_PARTITIONS = NULL;
|
free(VIRTUAL_FS_VOL[i].name);
|
||||||
MAX_VIRTUAL_PARTITIONS = 0;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_VIRTUAL_FS; i++) {
|
||||||
|
if (VIRTUAL_FS[i].name) {
|
||||||
|
free(VIRTUAL_FS[i].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIRTUAL_PARTITIONS) {
|
||||||
|
free(VIRTUAL_PARTITIONS);
|
||||||
|
}
|
||||||
|
if (VIRTUAL_FS_VOL) {
|
||||||
|
free(VIRTUAL_FS_VOL);
|
||||||
|
}
|
||||||
|
if (VIRTUAL_FS) {
|
||||||
|
free(VIRTUAL_FS);
|
||||||
|
}
|
||||||
|
VIRTUAL_PARTITIONS = NULL;
|
||||||
|
VIRTUAL_FS_VOL = NULL;
|
||||||
|
VIRTUAL_FS = NULL;
|
||||||
|
MAX_VIRTUAL_PARTITIONS = 0;
|
||||||
|
MAX_VIRTUAL_FS = 0;
|
||||||
|
MAX_VIRTUAL_FS_VOL = 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user