Skip to content

Commit

Permalink
fixed memory access violation
Browse files Browse the repository at this point in the history
  • Loading branch information
richterr committed Jun 23, 2020
1 parent 7e2e422 commit 031adad
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
22 changes: 20 additions & 2 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace hyenae

/* Methods */

template< class T >
template< class T>
void safe_delete(T*& ptr)
{
if (ptr != NULL)
Expand All @@ -88,7 +88,25 @@ namespace hyenae
}

} /* safe_delete */


template< class T>
void safe_delete(vector_t<T*> pointers)
{
T* current = NULL;

while (pointers.size() > 0)
{
current = pointers.front();
pointers.erase(pointers.begin());

if (current != NULL)
{
delete current;
}
}

} /* free_vector_pointers */

int64_t to_ms(duration_t duration);

string_t to_ms_string(duration_t duration);
Expand Down
1 change: 1 addition & 0 deletions include/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace hyenae
public:
using provider = func_t<file_io*()>;

virtual ~file_io() {}
virtual bool is_open() const = 0;
virtual void open(const string_t& filename, bool overwrite) = 0;
virtual void close() noexcept = 0;
Expand Down
13 changes: 6 additions & 7 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ namespace hyenae
}
catch (const exception_t& exception)
{
// TODO: Implement common method to free vector list of pointers,
// use method in all other classes too.
/*
for (auto section : sections)
if (sections.size() > 0)
{
safe_delete(section);
}
*/
// It is only required to delete the root section since all
// sub-sections will be delete by it's destructor.

safe_delete(sections.front());
}

throw runtime_error_t(exception.what());
}

Expand Down
11 changes: 2 additions & 9 deletions src/config_section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,8 @@ namespace hyenae

config::section::~section()
{
for (auto section : _sub_sections)
{
delete section;
}

for (auto value : _values)
{
delete value;
}
safe_delete(_sub_sections);
safe_delete(_values);

} /* ~section */

Expand Down
1 change: 1 addition & 0 deletions src/frontend/console/states/generator_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ namespace hyenae::frontend::console::states

generator_selector::~generator_selector()
{
// TODO: Replace with specific safe_delete method implementation
for (auto item : _menu_items)
{
delete item.first;
Expand Down
1 change: 1 addition & 0 deletions src/frontend/console/states/network_device_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace hyenae::frontend::console::states

network_device_selector::~network_device_selector()
{
// TODO: Replace with specific safe_delete method implementation
for (auto item : _menu_items)
{
delete item.first;
Expand Down
1 change: 1 addition & 0 deletions src/frontend/console/states/output_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace hyenae::frontend::console::states

output_setup::~output_setup()
{
// TODO: Replace with specific safe_delete method implementation
for (auto item : _menu_items)
{
delete item.first;
Expand Down

0 comments on commit 031adad

Please sign in to comment.