cleanup more memory leaks
This commit is contained in:
+25
-11
@@ -89,6 +89,7 @@ int validateAppId(const char * appIdStr) {
|
|||||||
int listGames(int argc, char ** argv) {
|
int listGames(int argc, char ** argv) {
|
||||||
if(argc != 2) return usage();
|
if(argc != 2) return usage();
|
||||||
GList * gamesIds = g_hash_table_get_keys(gamePaths);
|
GList * gamesIds = g_hash_table_get_keys(gamePaths);
|
||||||
|
GList * gamesIdsFirstPointer = gamesIds;
|
||||||
if(g_list_length(gamesIds) == 0) {
|
if(g_list_length(gamesIds) == 0) {
|
||||||
printf("No game found\n");
|
printf("No game found\n");
|
||||||
} else {
|
} else {
|
||||||
@@ -98,6 +99,7 @@ int listGames(int argc, char ** argv) {
|
|||||||
gamesIds = g_list_next(gamesIds);
|
gamesIds = g_list_next(gamesIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g_list_free(gamesIdsFirstPointer);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +163,8 @@ int installAndRemoveMod(int argc, char ** argv, bool install) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int returnValue = EXIT_SUCCESS;
|
||||||
|
|
||||||
//strtoul set EINVAL(after C99) if the string is invalid
|
//strtoul set EINVAL(after C99) if the string is invalid
|
||||||
u_int32_t modId = strtoul(argv[3], NULL, 10);
|
u_int32_t modId = strtoul(argv[3], NULL, 10);
|
||||||
if(errno == EINVAL) {
|
if(errno == EINVAL) {
|
||||||
@@ -188,7 +192,8 @@ int installAndRemoveMod(int argc, char ** argv, bool install) {
|
|||||||
if(install) {
|
if(install) {
|
||||||
if(access(modFlag, F_OK) == 0) {
|
if(access(modFlag, F_OK) == 0) {
|
||||||
printf("The mod is already activated \n");
|
printf("The mod is already activated \n");
|
||||||
return EXIT_SUCCESS;
|
returnValue = EXIT_SUCCESS;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create activated file
|
//Create activated file
|
||||||
@@ -198,19 +203,24 @@ int installAndRemoveMod(int argc, char ** argv, bool install) {
|
|||||||
} else {
|
} else {
|
||||||
if(access(modFlag, F_OK) != 0) {
|
if(access(modFlag, F_OK) != 0) {
|
||||||
printf("The mod is not activated \n");
|
printf("The mod is not activated \n");
|
||||||
return EXIT_SUCCESS;
|
returnValue = EXIT_SUCCESS;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unlink(modFlag) != 0) {
|
if(unlink(modFlag) != 0) {
|
||||||
printf("Error could not disable the mod.\n");
|
printf("Error could not disable the mod.\n");
|
||||||
printf("please remove this file '%s' as root\n", modFlag);
|
printf("please remove this file '%s' as root\n", modFlag);
|
||||||
return EXIT_FAILURE;
|
returnValue = EXIT_FAILURE;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(modFolder);
|
exit:
|
||||||
g_list_free(modsFirstPointer);
|
|
||||||
return EXIT_SUCCESS;
|
g_free(modFolder);
|
||||||
|
g_list_free_full(modsFirstPointer, free);
|
||||||
|
g_free(modFlag);
|
||||||
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int deploy(int argc, char ** argv) {
|
int deploy(int argc, char ** argv) {
|
||||||
@@ -339,6 +349,7 @@ int setup(int argc, char ** argv) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int unbind(int argc, char ** argv) {
|
int unbind(int argc, char ** argv) {
|
||||||
if(argc != 3 ) return usage();
|
if(argc != 3 ) return usage();
|
||||||
char * appIdStr = argv[2];
|
char * appIdStr = argv[2];
|
||||||
@@ -358,7 +369,6 @@ int unbind(int argc, char ** argv) {
|
|||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
if(argc < 2 ) return usage();
|
if(argc < 2 ) return usage();
|
||||||
|
|
||||||
|
|
||||||
if(audit_getloginuid() == 0) {
|
if(audit_getloginuid() == 0) {
|
||||||
printf("Root user should not be using this\n");
|
printf("Root user should not be using this\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -366,14 +376,17 @@ int main(int argc, char ** argv) {
|
|||||||
|
|
||||||
int searchStatus;
|
int searchStatus;
|
||||||
gamePaths = search_games(&searchStatus);
|
gamePaths = search_games(&searchStatus);
|
||||||
int returnValue = EXIT_SUCCESS;
|
|
||||||
|
|
||||||
|
int returnValue = EXIT_SUCCESS;
|
||||||
if(searchStatus == EXIT_FAILURE) {
|
if(searchStatus == EXIT_FAILURE) {
|
||||||
|
returnValue = EXIT_FAILURE;
|
||||||
printf("Error while looking up libraries, do you have steam installed ?");
|
printf("Error while looking up libraries, do you have steam installed ?");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * configFolder = g_build_filename(getHome(), MANAGER_FILES, NULL);
|
char * home = getHome();
|
||||||
|
char * configFolder = g_build_filename(home, MANAGER_FILES, NULL);
|
||||||
|
free(home);
|
||||||
if(access(configFolder, F_OK) != 0) {
|
if(access(configFolder, F_OK) != 0) {
|
||||||
|
|
||||||
//check to NOT run this as root
|
//check to NOT run this as root
|
||||||
@@ -394,7 +407,7 @@ int main(int argc, char ** argv) {
|
|||||||
//failure would have no impact
|
//failure would have no impact
|
||||||
char * chattrcommand = g_strjoin("", "chattr +F ",configFolder, " 2> /dev/null", NULL);
|
char * chattrcommand = g_strjoin("", "chattr +F ",configFolder, " 2> /dev/null", NULL);
|
||||||
system(chattrcommand);
|
system(chattrcommand);
|
||||||
free(chattrcommand);
|
g_free(chattrcommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +465,8 @@ int main(int argc, char ** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit2:
|
exit2:
|
||||||
free(configFolder);
|
g_free(configFolder);
|
||||||
|
g_hash_table_destroy(gamePaths);
|
||||||
exit:
|
exit:
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -99,6 +99,7 @@ ValveLibraries_t * parseVDF(const char * path, size_t * size, int * status) {
|
|||||||
|
|
||||||
case FIELD_TOTAL_SIZE:
|
case FIELD_TOTAL_SIZE:
|
||||||
library->totalSize = strtoul(value, NULL, 0);
|
library->totalSize = strtoul(value, NULL, 0);
|
||||||
|
free(value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIELD_CLEAN_BYTES:
|
case FIELD_CLEAN_BYTES:
|
||||||
@@ -162,6 +163,7 @@ ValveLibraries_t * parseVDF(const char * path, size_t * size, int * status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if(line != NULL) free(line);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return libraries;
|
return libraries;
|
||||||
}
|
}
|
||||||
@@ -189,8 +191,10 @@ GHashTable* search_games(int * status) {
|
|||||||
if (access(path, F_OK) == 0) {
|
if (access(path, F_OK) == 0) {
|
||||||
int parserStatus;
|
int parserStatus;
|
||||||
libraries = parseVDF(path, &size, &parserStatus);
|
libraries = parseVDF(path, &size, &parserStatus);
|
||||||
if(parserStatus == EXIT_SUCCESS)
|
if(parserStatus == EXIT_SUCCESS) {
|
||||||
|
g_free(path);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(path);
|
g_free(path);
|
||||||
@@ -202,7 +206,7 @@ GHashTable* search_games(int * status) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GHashTable* table = g_hash_table_new(g_int_hash, g_int_equal);
|
GHashTable* table = g_hash_table_new_full(g_int_hash, g_int_equal, free, free);
|
||||||
|
|
||||||
//fill the table
|
//fill the table
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user