fixed attempt to free a non allocated string

This commit is contained in:
jmjatlanta 2017-09-26 09:43:10 -05:00
parent 5bcd3a99f2
commit 2cc7f52fbf
6 changed files with 32 additions and 26 deletions

View file

@ -6,6 +6,7 @@
#include "ipfs/importer/importer.h"
#include "ipfs/merkledag/merkledag.h"
#include "libp2p/os/utils.h"
#include "ipfs/cmd/cli.h"
#include "ipfs/core/ipfs_node.h"
#include "ipfs/repo/fsrepo/fs_repo.h"
#include "ipfs/repo/init.h"
@ -312,26 +313,17 @@ int ipfs_import_file(const char* root_dir, const char* fileName, struct Hashtabl
* @param argv command line parameters
* @returns a FileList linked list of filenames
*/
struct FileList* ipfs_import_get_filelist(int argc, char** argv) {
struct FileList* ipfs_import_get_filelist(struct CliArguments* args) {
struct FileList* first = NULL;
struct FileList* last = NULL;
int skipNext = 0;
for (int i = 2; i < argc; i++) {
if (skipNext) {
skipNext = 0;
continue;
}
if (strcmp(argv[i], "-r") == 0) {
continue;
}
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) {
skipNext = 1;
for (int i = args->verb_index + 1; i < args->argc; i++) {
if (strcmp(args->argv[i], "add") == 0) {
continue;
}
struct FileList* current = (struct FileList*)malloc(sizeof(struct FileList));
current->next = NULL;
current->file_name = argv[i];
current->file_name = args->argv[i];
// now wire it in
if (first == NULL) {
first = current;
@ -364,7 +356,7 @@ int ipfs_import_is_recursive(int argc, char** argv) {
* @param argc the number of arguments
* @param argv the arguments
*/
int ipfs_import_files(int argc, char** argv) {
int ipfs_import_files(struct CliArguments* args) {
/*
* Param 0: ipfs
* param 1: add
@ -380,17 +372,17 @@ int ipfs_import_files(int argc, char** argv) {
char* filename = NULL;
struct HashtableNode* directory_entry = NULL;
int recursive = ipfs_import_is_recursive(argc, argv);
int recursive = ipfs_import_is_recursive(args->argc, args->argv);
// parse the command line
first = ipfs_import_get_filelist(argc, argv);
first = ipfs_import_get_filelist(args);
// open the repo
if (!ipfs_repo_get_directory(argc, argv, &repo_path)) {
if (!ipfs_repo_get_directory(args->argc, args->argv, &repo_path)) {
fprintf(stderr, "Repo does not exist: %s\n", repo_path);
goto exit;
}
ipfs_node_online_new(repo_path, &local_node);
ipfs_node_offline_new(repo_path, &local_node);
// import the file(s)
@ -434,8 +426,8 @@ int ipfs_import_files(int argc, char** argv) {
free(filename);
if (directory_entry != NULL)
ipfs_hashtable_node_free(directory_entry);
if (repo_path != NULL)
free(repo_path);
//if (repo_path != NULL)
// free(repo_path);
return retVal;
}

View file

@ -1,6 +1,7 @@
#ifndef __IPFS_IMPORTER_IMPORTER_H__
#define __IPFS_IMPORTER_IMPORTER_H__
#include "ipfs/cmd/cli.h"
#include "ipfs/merkledag/node.h"
#include "ipfs/core/ipfs_node.h"
@ -26,6 +27,6 @@ int ipfs_import_file(const char* root, const char* fileName, struct HashtableNod
* @param argc the number of arguments
* @param argv the arguments
*/
int ipfs_import_files(int argc, char** argv);
int ipfs_import_files(struct CliArguments* args);
#endif /* INCLUDE_IPFS_IMPORTER_IMPORTER_H_ */

View file

@ -162,7 +162,7 @@ int main(int argc, char** argv) {
return ipfs_repo_init(argc, argv);
break;
case (ADD):
ipfs_import_files(argc, argv);
ipfs_import_files(args);
break;
case (OBJECT_GET):
ipfs_exporter_object_get(argc, argv);

View file

@ -63,6 +63,7 @@ int test_core_api_object_cat() {
struct FSRepo* fs_repo = NULL;
char hash[256] = "";
char* args[] = {"ipfs", "--config", ipfs_path2, "cat", hash };
struct CliArguments* arguments = NULL;
// logging
libp2p_logger_add_class("test_api");
@ -126,7 +127,7 @@ int test_core_api_object_cat() {
sleep(3);
// use a client to ask for the file on server 1
struct CliArguments* arguments = cli_arguments_new(5, args);
arguments = cli_arguments_new(5, args);
if (ipfs_exporter_object_cat(arguments) == 0) {
libp2p_logger_error("test_api", "ipfs_exporter_object_cat returned false.\n");
goto exit;

View file

@ -1,5 +1,6 @@
#include <pthread.h>
#include "ipfs/cmd/cli.h"
#include "ipfs/importer/resolver.h"
#include "libp2p/os/utils.h"
#include "multiaddr/multiaddr.h"
@ -15,6 +16,7 @@ int test_resolver_get() {
char* argv[argc];
const char* work_path = "/tmp";
char ipfs_path[12];
struct CliArguments* arguments = NULL;
sprintf(&ipfs_path[0], "%s/%s", work_path, ".ipfs");
os_utils_filepath_join(home_dir, "ipfstest", test_dir, strlen(home_dir) + 10);
@ -30,7 +32,8 @@ int test_resolver_get() {
argv[4] = "-c";
argv[5] = (char*)work_path;
ipfs_import_files(argc, (char**)argv);
arguments = cli_arguments_new(6, (char**)&argv);
ipfs_import_files(arguments);
ipfs_repo_fsrepo_new(ipfs_path, NULL, &fs_repo);
ipfs_repo_fsrepo_open(fs_repo);
@ -73,6 +76,7 @@ int test_resolver_get() {
free(test_dir);
ipfs_repo_fsrepo_free(fs_repo);
ipfs_hashtable_node_free(result);
cli_arguments_free(arguments);
return retVal;
}
@ -87,6 +91,7 @@ int test_resolver_remote_get() {
int retVal = 0;
struct FSRepo* fs_repo = NULL;
struct HashtableNode* result = NULL;
struct CliArguments* arguments;
// this should point to a test directory with files and directories
char* home_dir = os_utils_get_homedir();
@ -99,6 +104,8 @@ int test_resolver_remote_get() {
argv[2] = "-r";
argv[3] = test_dir;
arguments = cli_arguments_new(4, (char**)&argv);
drop_and_build_repository(ipfs_path, 4001, NULL, NULL);
// start the daemon in a separate thread
@ -108,7 +115,7 @@ int test_resolver_remote_get() {
os_utils_filepath_join(home_dir, "ipfstest", test_dir, strlen(home_dir) + 10);
ipfs_import_files(argc, (char**)argv);
ipfs_import_files(arguments);
ipfs_repo_fsrepo_new(ipfs_path, NULL, &fs_repo);
ipfs_repo_fsrepo_open(fs_repo);
@ -149,6 +156,7 @@ int test_resolver_remote_get() {
ipfs_repo_fsrepo_free(fs_repo);
if (local_node.peerstore != NULL)
libp2p_peerstore_free(local_node.peerstore);
cli_arguments_free(arguments);
return retVal;
}

View file

@ -8,6 +8,7 @@
#include "multiaddr/multiaddr.h"
#include "ipfs/cmd/cli.h"
#include "ipfs/core/daemon.h"
#include "ipfs/core/ipfs_node.h"
#include "ipfs/routing/routing.h"
@ -32,6 +33,7 @@ int test_routing_put_value() {
char* peer_id_consumer = NULL;
int consumer_thread_started = 0;
struct Libp2pVector* ma_vector = NULL;
struct CliArguments* arguments = NULL;
// fire up the "publisher"
drop_and_build_repository(ipfs_path_publisher, 4001, NULL, &peer_id_publisher);
@ -39,7 +41,8 @@ int test_routing_put_value() {
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_publisher);
ma_publisher = multiaddress_new_from_string(multiaddress_string);
char* args[] = { "ipfs", "--config", ipfs_path_publisher, "add", "-r", "~/site"};
ipfs_import_files(6, args);
arguments = cli_arguments_new(6, args);
ipfs_import_files(arguments);
if (!pthread_create(&thread_publisher, NULL, test_daemon_start, (void*)ipfs_path_publisher)) {
goto exit;
}
@ -82,6 +85,7 @@ int test_routing_put_value() {
pthread_join(thread_consumer, NULL);
}
multiaddress_free(ma_publisher);
cli_arguments_free(arguments);
return retVal;
}