fixed attempt to free a non allocated string
This commit is contained in:
parent
5bcd3a99f2
commit
2cc7f52fbf
6 changed files with 32 additions and 26 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "ipfs/importer/importer.h"
|
#include "ipfs/importer/importer.h"
|
||||||
#include "ipfs/merkledag/merkledag.h"
|
#include "ipfs/merkledag/merkledag.h"
|
||||||
#include "libp2p/os/utils.h"
|
#include "libp2p/os/utils.h"
|
||||||
|
#include "ipfs/cmd/cli.h"
|
||||||
#include "ipfs/core/ipfs_node.h"
|
#include "ipfs/core/ipfs_node.h"
|
||||||
#include "ipfs/repo/fsrepo/fs_repo.h"
|
#include "ipfs/repo/fsrepo/fs_repo.h"
|
||||||
#include "ipfs/repo/init.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
|
* @param argv command line parameters
|
||||||
* @returns a FileList linked list of filenames
|
* @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* first = NULL;
|
||||||
struct FileList* last = NULL;
|
struct FileList* last = NULL;
|
||||||
int skipNext = 0;
|
|
||||||
|
|
||||||
for (int i = 2; i < argc; i++) {
|
for (int i = args->verb_index + 1; i < args->argc; i++) {
|
||||||
if (skipNext) {
|
if (strcmp(args->argv[i], "add") == 0) {
|
||||||
skipNext = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strcmp(argv[i], "-r") == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) {
|
|
||||||
skipNext = 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct FileList* current = (struct FileList*)malloc(sizeof(struct FileList));
|
struct FileList* current = (struct FileList*)malloc(sizeof(struct FileList));
|
||||||
current->next = NULL;
|
current->next = NULL;
|
||||||
current->file_name = argv[i];
|
current->file_name = args->argv[i];
|
||||||
// now wire it in
|
// now wire it in
|
||||||
if (first == NULL) {
|
if (first == NULL) {
|
||||||
first = current;
|
first = current;
|
||||||
|
@ -364,7 +356,7 @@ int ipfs_import_is_recursive(int argc, char** argv) {
|
||||||
* @param argc the number of arguments
|
* @param argc the number of arguments
|
||||||
* @param argv the arguments
|
* @param argv the arguments
|
||||||
*/
|
*/
|
||||||
int ipfs_import_files(int argc, char** argv) {
|
int ipfs_import_files(struct CliArguments* args) {
|
||||||
/*
|
/*
|
||||||
* Param 0: ipfs
|
* Param 0: ipfs
|
||||||
* param 1: add
|
* param 1: add
|
||||||
|
@ -380,17 +372,17 @@ int ipfs_import_files(int argc, char** argv) {
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
struct HashtableNode* directory_entry = 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
|
// parse the command line
|
||||||
first = ipfs_import_get_filelist(argc, argv);
|
first = ipfs_import_get_filelist(args);
|
||||||
|
|
||||||
// open the repo
|
// 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);
|
fprintf(stderr, "Repo does not exist: %s\n", repo_path);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
ipfs_node_online_new(repo_path, &local_node);
|
ipfs_node_offline_new(repo_path, &local_node);
|
||||||
|
|
||||||
|
|
||||||
// import the file(s)
|
// import the file(s)
|
||||||
|
@ -434,8 +426,8 @@ int ipfs_import_files(int argc, char** argv) {
|
||||||
free(filename);
|
free(filename);
|
||||||
if (directory_entry != NULL)
|
if (directory_entry != NULL)
|
||||||
ipfs_hashtable_node_free(directory_entry);
|
ipfs_hashtable_node_free(directory_entry);
|
||||||
if (repo_path != NULL)
|
//if (repo_path != NULL)
|
||||||
free(repo_path);
|
// free(repo_path);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef __IPFS_IMPORTER_IMPORTER_H__
|
#ifndef __IPFS_IMPORTER_IMPORTER_H__
|
||||||
#define __IPFS_IMPORTER_IMPORTER_H__
|
#define __IPFS_IMPORTER_IMPORTER_H__
|
||||||
|
|
||||||
|
#include "ipfs/cmd/cli.h"
|
||||||
#include "ipfs/merkledag/node.h"
|
#include "ipfs/merkledag/node.h"
|
||||||
#include "ipfs/core/ipfs_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 argc the number of arguments
|
||||||
* @param argv the 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_ */
|
#endif /* INCLUDE_IPFS_IMPORTER_IMPORTER_H_ */
|
||||||
|
|
|
@ -162,7 +162,7 @@ int main(int argc, char** argv) {
|
||||||
return ipfs_repo_init(argc, argv);
|
return ipfs_repo_init(argc, argv);
|
||||||
break;
|
break;
|
||||||
case (ADD):
|
case (ADD):
|
||||||
ipfs_import_files(argc, argv);
|
ipfs_import_files(args);
|
||||||
break;
|
break;
|
||||||
case (OBJECT_GET):
|
case (OBJECT_GET):
|
||||||
ipfs_exporter_object_get(argc, argv);
|
ipfs_exporter_object_get(argc, argv);
|
||||||
|
|
|
@ -63,6 +63,7 @@ int test_core_api_object_cat() {
|
||||||
struct FSRepo* fs_repo = NULL;
|
struct FSRepo* fs_repo = NULL;
|
||||||
char hash[256] = "";
|
char hash[256] = "";
|
||||||
char* args[] = {"ipfs", "--config", ipfs_path2, "cat", hash };
|
char* args[] = {"ipfs", "--config", ipfs_path2, "cat", hash };
|
||||||
|
struct CliArguments* arguments = NULL;
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
libp2p_logger_add_class("test_api");
|
libp2p_logger_add_class("test_api");
|
||||||
|
@ -126,7 +127,7 @@ int test_core_api_object_cat() {
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
// use a client to ask for the file on server 1
|
// 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) {
|
if (ipfs_exporter_object_cat(arguments) == 0) {
|
||||||
libp2p_logger_error("test_api", "ipfs_exporter_object_cat returned false.\n");
|
libp2p_logger_error("test_api", "ipfs_exporter_object_cat returned false.\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#include "ipfs/cmd/cli.h"
|
||||||
#include "ipfs/importer/resolver.h"
|
#include "ipfs/importer/resolver.h"
|
||||||
#include "libp2p/os/utils.h"
|
#include "libp2p/os/utils.h"
|
||||||
#include "multiaddr/multiaddr.h"
|
#include "multiaddr/multiaddr.h"
|
||||||
|
@ -15,6 +16,7 @@ int test_resolver_get() {
|
||||||
char* argv[argc];
|
char* argv[argc];
|
||||||
const char* work_path = "/tmp";
|
const char* work_path = "/tmp";
|
||||||
char ipfs_path[12];
|
char ipfs_path[12];
|
||||||
|
struct CliArguments* arguments = NULL;
|
||||||
sprintf(&ipfs_path[0], "%s/%s", work_path, ".ipfs");
|
sprintf(&ipfs_path[0], "%s/%s", work_path, ".ipfs");
|
||||||
|
|
||||||
os_utils_filepath_join(home_dir, "ipfstest", test_dir, strlen(home_dir) + 10);
|
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[4] = "-c";
|
||||||
argv[5] = (char*)work_path;
|
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_new(ipfs_path, NULL, &fs_repo);
|
||||||
ipfs_repo_fsrepo_open(fs_repo);
|
ipfs_repo_fsrepo_open(fs_repo);
|
||||||
|
@ -73,6 +76,7 @@ int test_resolver_get() {
|
||||||
free(test_dir);
|
free(test_dir);
|
||||||
ipfs_repo_fsrepo_free(fs_repo);
|
ipfs_repo_fsrepo_free(fs_repo);
|
||||||
ipfs_hashtable_node_free(result);
|
ipfs_hashtable_node_free(result);
|
||||||
|
cli_arguments_free(arguments);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +91,7 @@ int test_resolver_remote_get() {
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
struct FSRepo* fs_repo = NULL;
|
struct FSRepo* fs_repo = NULL;
|
||||||
struct HashtableNode* result = NULL;
|
struct HashtableNode* result = NULL;
|
||||||
|
struct CliArguments* arguments;
|
||||||
|
|
||||||
// this should point to a test directory with files and directories
|
// this should point to a test directory with files and directories
|
||||||
char* home_dir = os_utils_get_homedir();
|
char* home_dir = os_utils_get_homedir();
|
||||||
|
@ -99,6 +104,8 @@ int test_resolver_remote_get() {
|
||||||
argv[2] = "-r";
|
argv[2] = "-r";
|
||||||
argv[3] = test_dir;
|
argv[3] = test_dir;
|
||||||
|
|
||||||
|
arguments = cli_arguments_new(4, (char**)&argv);
|
||||||
|
|
||||||
drop_and_build_repository(ipfs_path, 4001, NULL, NULL);
|
drop_and_build_repository(ipfs_path, 4001, NULL, NULL);
|
||||||
|
|
||||||
// start the daemon in a separate thread
|
// 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);
|
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_new(ipfs_path, NULL, &fs_repo);
|
||||||
ipfs_repo_fsrepo_open(fs_repo);
|
ipfs_repo_fsrepo_open(fs_repo);
|
||||||
|
@ -149,6 +156,7 @@ int test_resolver_remote_get() {
|
||||||
ipfs_repo_fsrepo_free(fs_repo);
|
ipfs_repo_fsrepo_free(fs_repo);
|
||||||
if (local_node.peerstore != NULL)
|
if (local_node.peerstore != NULL)
|
||||||
libp2p_peerstore_free(local_node.peerstore);
|
libp2p_peerstore_free(local_node.peerstore);
|
||||||
|
cli_arguments_free(arguments);
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "multiaddr/multiaddr.h"
|
#include "multiaddr/multiaddr.h"
|
||||||
|
|
||||||
|
#include "ipfs/cmd/cli.h"
|
||||||
#include "ipfs/core/daemon.h"
|
#include "ipfs/core/daemon.h"
|
||||||
#include "ipfs/core/ipfs_node.h"
|
#include "ipfs/core/ipfs_node.h"
|
||||||
#include "ipfs/routing/routing.h"
|
#include "ipfs/routing/routing.h"
|
||||||
|
@ -32,6 +33,7 @@ int test_routing_put_value() {
|
||||||
char* peer_id_consumer = NULL;
|
char* peer_id_consumer = NULL;
|
||||||
int consumer_thread_started = 0;
|
int consumer_thread_started = 0;
|
||||||
struct Libp2pVector* ma_vector = NULL;
|
struct Libp2pVector* ma_vector = NULL;
|
||||||
|
struct CliArguments* arguments = NULL;
|
||||||
|
|
||||||
// fire up the "publisher"
|
// fire up the "publisher"
|
||||||
drop_and_build_repository(ipfs_path_publisher, 4001, NULL, &peer_id_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);
|
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_publisher);
|
||||||
ma_publisher = multiaddress_new_from_string(multiaddress_string);
|
ma_publisher = multiaddress_new_from_string(multiaddress_string);
|
||||||
char* args[] = { "ipfs", "--config", ipfs_path_publisher, "add", "-r", "~/site"};
|
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)) {
|
if (!pthread_create(&thread_publisher, NULL, test_daemon_start, (void*)ipfs_path_publisher)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +85,7 @@ int test_routing_put_value() {
|
||||||
pthread_join(thread_consumer, NULL);
|
pthread_join(thread_consumer, NULL);
|
||||||
}
|
}
|
||||||
multiaddress_free(ma_publisher);
|
multiaddress_free(ma_publisher);
|
||||||
|
cli_arguments_free(arguments);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue