Skip to content

Commit

Permalink
[kpm] Memory leaks and segfaults in erase agents tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaZotov committed Apr 15, 2023
1 parent 9d9bb3b commit 8f44fe0
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 33 deletions.
5 changes: 3 additions & 2 deletions sc-kpm/tests/sc-utils/sc-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ TEST_F(ScMemoryTest, erase_elements_from_init_struct)

sleep(2);

sc_iterator3 * it = sc_iterator3_f_a_f_new(context, setAddr, 0, testAddr);
sc_iterator3 * it = sc_iterator3_f_a_a_new(context, setAddr, 0, 0);
EXPECT_TRUE(sc_iterator3_next(it));
EXPECT_FALSE(sc_iterator3_next(it));
sc_iterator3_free(it);

sc_memory_context_free(context);
Expand Down Expand Up @@ -103,7 +104,7 @@ TEST_F(ScMemoryTest, erase_elements_self_erase)
sc_module_shutdown();
}

TEST_F(ScMemoryTest, erase_elements_set_node_erase)
TEST_F(ScMemoryTest, erase_elements_erase_keynode)
{
sc_memory_context * context = sc_memory_context_new(sc_access_lvl_make_min);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ sc_dictionary_fs_memory_status sc_dictionary_fs_memory_initialize(
static sc_char const * string_offsets_link_hashes = "string_offsets_link_hashes" SC_FS_EXT;
sc_fs_initialize_file_path(path, string_offsets_link_hashes, &(*memory)->string_offsets_link_hashes_path);
}
sc_fs_memory_info("Configuration: ");
sc_message("\tpath: %s", path);
sc_message("\tmax searchable string size: %s", path);
sc_fs_memory_info("Configuration:");
sc_message("\tRepo path: %s", path);
sc_message("\tSc-dictionary node size: %zd", sizeof(sc_dictionary_node));
sc_message("\tMax searchable string size: %s", path);

sc_fs_memory_info("Successfully initialized");

Expand Down
2 changes: 1 addition & 1 deletion sc-memory/sc-core/sc-store/sc-fs-memory/sc_fs_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sc_bool sc_fs_memory_shutdown()
sc_mem_free(manager->segments_path);
sc_mem_free(manager);

return SC_FALSE;
return SC_TRUE;
}

sc_bool sc_fs_memory_link_string(sc_addr_hash const link_hash, sc_char const * string, sc_uint32 const string_size)
Expand Down
4 changes: 4 additions & 0 deletions sc-memory/sc-core/sc-store/sc_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ sc_bool sc_storage_initialize(const char * path, sc_bool clear)
if (sc_fs_memory_load(segments, &segments_num) != SC_TRUE)
return SC_FALSE;
}
else
{
segments_num = 0;
}

is_initialized = SC_TRUE;
return SC_TRUE;
Expand Down
17 changes: 14 additions & 3 deletions sc-memory/sc-core/sc_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ sc_memory_context * sc_memory_initialize(const sc_memory_params * params)

sc_memory_info("Version: %s", params->version);
sc_message("\tClean memory on shutdown: %s", params->clear ? "On" : "Off");
sc_message("\tRepo path: %s", params->repo_path);
sc_message("\tExtension path: %s", params->ext_path);
sc_message("\tExtensions path: %s", params->ext_path);
sc_message("\tSave period: %d", params->save_period);
sc_message("\tUpdate period: %d", params->update_period);

Expand All @@ -49,7 +48,6 @@ sc_memory_context * sc_memory_initialize(const sc_memory_params * params)
sc_message("\tmax loaded segments: %d", params->max_loaded_segments);
sc_message("\tmax threads: %d", params->max_threads);
sc_message("\tsc-element size: %zd", sizeof(sc_element));
sc_message("\tsc-string-node size: %zd", sizeof(sc_dictionary_node));

sc_memory_info("Build configuration:");
sc_message("\tResult structure upload: %s", params->init_memory_generated_upload ? "On" : "Off");
Expand Down Expand Up @@ -80,6 +78,19 @@ sc_memory_context * sc_memory_initialize(const sc_memory_params * params)
goto error;
}

sc_addr init_memory_generated_structure;
if (params->init_memory_generated_upload)
sc_helper_resolve_system_identifier(
s_memory_default_ctx, params->init_memory_generated_structure, &init_memory_generated_structure);
else
SC_ADDR_MAKE_EMPTY(init_memory_generated_structure);

if (sc_memory_init_ext(params->ext_path, params->enabled_exts, init_memory_generated_structure) != SC_RESULT_OK)
{
sc_memory_error("Error while initialize extensions");
goto error;
}

sc_memory_info("All components successfully initialized");
return s_memory_default_ctx;

Expand Down
10 changes: 0 additions & 10 deletions sc-memory/sc-memory/sc_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,10 @@ bool ScMemory::Initialize(sc_memory_params const & params)
if (ms_globalContext == nullptr)
return false;

sc_addr init_memory_generated_structure;
if (params.init_memory_generated_upload)
sc_helper_resolve_system_identifier(
ms_globalContext, params.init_memory_generated_structure, &init_memory_generated_structure);
else
SC_ADDR_MAKE_EMPTY(init_memory_generated_structure);

ScKeynodes::Init(
false, params.init_memory_generated_upload ? params.init_memory_generated_structure : (sc_char *)null_ptr);
ScAgentInit(true);

if (sc_memory_init_ext(params.ext_path, params.enabled_exts, init_memory_generated_structure) != SC_RESULT_OK)
return false;

utils::ScLog::SetUp(params.log_type, params.log_file, params.log_level);

return (ms_globalContext != nullptr);
Expand Down
12 changes: 8 additions & 4 deletions sc-memory/tests/sc-memory/containers/sc-dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void _test_sc_dictionary_addr_hashes_char_to_int(sc_char ch, sc_uint8 * ch_num,

sc_bool _test_sc_uchar_dictionary_initialize(sc_dictionary ** dictionary)
{
return sc_dictionary_initialize(dictionary, _test_sc_dictionary_addr_hashes_children_size(), _test_sc_dictionary_addr_hashes_char_to_int);
return sc_dictionary_initialize(
dictionary, _test_sc_dictionary_addr_hashes_children_size(), _test_sc_dictionary_addr_hashes_char_to_int);
}

sc_bool _test_sc_uchar_dictionary_destroy(sc_dictionary * dictionary)
Expand Down Expand Up @@ -179,7 +180,8 @@ TEST(ScDictionaryTest, sc_dictionary_append_get_by_key_prefix)

sc_list * hashes;
sc_list_init(&hashes);
sc_dictionary_get_by_key_prefix(dictionary, search_string1, search_string1_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
sc_dictionary_get_by_key_prefix(
dictionary, search_string1, search_string1_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
EXPECT_EQ(hashes->size, 3u);

EXPECT_TRUE(sc_list_remove_if(hashes, (void *)hash1, _test_sc_hashes_compare));
Expand All @@ -192,7 +194,8 @@ TEST(ScDictionaryTest, sc_dictionary_append_get_by_key_prefix)
sc_uint32 search_string2_size = sc_str_len(search_string2);

sc_list_init(&hashes);
sc_dictionary_get_by_key_prefix(dictionary, search_string2, search_string2_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
sc_dictionary_get_by_key_prefix(
dictionary, search_string2, search_string2_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
EXPECT_EQ(hashes->size, 2u);

EXPECT_TRUE(sc_list_remove_if(hashes, (void *)hash1, _test_sc_hashes_compare));
Expand All @@ -205,7 +208,8 @@ TEST(ScDictionaryTest, sc_dictionary_append_get_by_key_prefix)
sc_uint32 search_string3_size = sc_str_len(search_string2);

sc_list_init(&hashes);
sc_dictionary_get_by_key_prefix(dictionary, search_string3, search_string3_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
sc_dictionary_get_by_key_prefix(
dictionary, search_string3, search_string3_size, _test_visit_nodes_by_key_prefix, (void **)&hashes);
EXPECT_EQ(hashes->size, 1u);

EXPECT_FALSE(sc_list_remove_if(hashes, (void *)hash1, _test_sc_hashes_compare));
Expand Down
1 change: 0 additions & 1 deletion sc-memory/tests/sc-memory/containers/sc-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ TEST_F(ScListTest, sc_list_iterator)
sc_iterator_destroy(it);
sc_list_destroy(list);
}

9 changes: 3 additions & 6 deletions sc-memory/tests/sc-memory/fs-storage/sc-fs-storage-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ TEST(ScDictionaryFsMemoryTest, sc_dictionary_fs_memory_get_strings_by_substring)
sc_list * found_strings;
sc_char substring1[] = "it";
EXPECT_EQ(
sc_dictionary_fs_memory_get_strings_by_substring(
memory, substring1, sc_str_len(substring1), &found_strings),
sc_dictionary_fs_memory_get_strings_by_substring(memory, substring1, sc_str_len(substring1), &found_strings),
SC_FS_MEMORY_OK);
EXPECT_EQ(found_strings->size, 2u);

Expand All @@ -541,8 +540,7 @@ TEST(ScDictionaryFsMemoryTest, sc_dictionary_fs_memory_get_strings_by_substring)

sc_char substring2[] = "it is the first";
EXPECT_EQ(
sc_dictionary_fs_memory_get_strings_by_substring(
memory, substring2, sc_str_len(substring2), &found_strings),
sc_dictionary_fs_memory_get_strings_by_substring(memory, substring2, sc_str_len(substring2), &found_strings),
SC_FS_MEMORY_OK);
EXPECT_EQ(found_strings->size, 1u);

Expand All @@ -555,8 +553,7 @@ TEST(ScDictionaryFsMemoryTest, sc_dictionary_fs_memory_get_strings_by_substring)

sc_char substring3[] = "it is the second";
EXPECT_EQ(
sc_dictionary_fs_memory_get_strings_by_substring(
memory, substring3, sc_str_len(substring3), &found_strings),
sc_dictionary_fs_memory_get_strings_by_substring(memory, substring3, sc_str_len(substring3), &found_strings),
SC_FS_MEMORY_OK);
EXPECT_EQ(found_strings->size, 1u);

Expand Down
2 changes: 1 addition & 1 deletion sc-tools/sc-builder/src/scs_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FileProvider : public SCsFileInterface
std::string const extension = fullPath.substr(fullPath.rfind('.'));
sc_char * copied;
sc_str_cpy(copied, fullPath.c_str(), fullPath.size());
return std::make_shared<ScStream>(copied, fullPath.size(), SC_STREAM_FLAG_READ);
return std::make_shared<ScStream>(copied, fullPath.size(), SC_STREAM_FLAG_READ, SC_TRUE);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions sc-tools/sc-builder/tests/units/test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ TEST(ScBuilder, RunStop)

ScParams memoryParams{options, {}};
memoryParams.insert({"repo_path", SC_BUILDER_REPO_PATH});
memoryParams.insert({"clear", "true"});

ScConfig configFile{config, {"repo_path"}};
std::string memoryGroupName = "sc-memory";

ScMemoryConfig memoryConfig{configFile, std::move(memoryParams)};
ScMemoryConfig memoryConfig{configFile, memoryParams};

Builder builder;
EXPECT_TRUE(builder.Run(params, memoryConfig.GetParams()));
Expand Down

0 comments on commit 8f44fe0

Please sign in to comment.