memory cleanup reorganized

xethyrion-master
jmjatlanta 2016-11-02 13:44:56 -05:00
parent 0d8f599ac9
commit d30fa55af7
6 changed files with 26 additions and 0 deletions

View File

@ -74,4 +74,11 @@ int config_path(char* config_root, char* extension, char* result, int max_len);
*/
int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypair, char* repo_path);
/***
* free all resources that were allocated to store config information
* @param config the config
* @returns true(1)
*/
int repo_config_free(struct RepoConfig* config);
#endif

View File

@ -32,5 +32,6 @@ int repo_config_addresses_init(struct Addresses* addresses, char* api, char* gat
int repo_config_addresses_free(struct Addresses* addresses) {
free(addresses->api);
free(addresses->gateway);
repo_config_swarm_address_free(&(addresses->swarm));
return 1;
}

View File

@ -7,6 +7,7 @@
//
#include <stdio.h>
#include "mbedtls/base64.h"
/**
* encode using base64

View File

@ -134,3 +134,14 @@ int repo_config_init(struct RepoConfig* config, unsigned int num_bits_for_keypai
return 1;
}
int repo_config_free(struct RepoConfig* config) {
repo_config_bootstrap_peers_free(&(config->peer_addresses));
repo_config_datastore_free(&(config->datastore));
repo_config_addresses_free(&(config->addresses));
return 1;
}
int repo_config_martial_to_json(struct RepoConfig* config) {
return 0;
}

View File

@ -100,6 +100,9 @@ int fs_repo_open(char* repo_path, struct FSRepo* repo) {
//TODO: lock
// get the path set in the repo struct
int retVal = repo_new_fs_repo(repo_path, repo);
if (retVal == 0)
return 0;
// check if initialized
if (!repo_check_initialized(repo->path))
return 0;

View File

@ -16,6 +16,7 @@ int test_repo_config_init() {
int retVal = repo_config_init(&repoConfig, 2048, "/Users/JohnJones/.ipfs");
if (retVal == 0)
return 0;
// now tear it apart to check for anything broken
// addresses
@ -31,6 +32,8 @@ int test_repo_config_init() {
if (retVal != 0)
return 0;
repo_config_free(&repoConfig);
return 1;
}