Fix memory leak from auparse_get_node

This commit is contained in:
Aleksei Nikiforov 2020-01-23 17:40:54 +03:00
parent 62adea5afd
commit 972da5776a
3 changed files with 11 additions and 1 deletions

View File

@ -229,7 +229,7 @@ void auparse_callback(auparse_state_t *au, auparse_cb_event_t cb_event_type, voi
audit_record.time = auparse_get_time(au); audit_record.time = auparse_get_time(au);
audit_record.milliseconds = auparse_get_milli(au); audit_record.milliseconds = auparse_get_milli(au);
audit_record.serial = auparse_get_serial(au); audit_record.serial = auparse_get_serial(au);
audit_record.node = string_or_null(auparse_get_node(au)); audit_record.node = string_or_null_and_free(auparse_get_node(au));
if (auparse_first_field(au) > 0) if (auparse_first_field(au) > 0)
{ {

View File

@ -20,11 +20,20 @@
#include "utils.hpp" #include "utils.hpp"
#include <stdlib.h>
std::string string_or_null(const char *data) std::string string_or_null(const char *data)
{ {
return (data) ? data : std::string(); return (data) ? data : std::string();
} }
std::string string_or_null_and_free(const char *data)
{
std::string result = string_or_null(data);
free((void*) data);
return result;
}
std::string sanitize_column_name(const std::string &name) std::string sanitize_column_name(const std::string &name)
{ {
auto result = name; auto result = name;

View File

@ -26,6 +26,7 @@
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
std::string string_or_null(const char *data); std::string string_or_null(const char *data);
std::string string_or_null_and_free(const char *data);
std::string sanitize_column_name(const std::string &name); std::string sanitize_column_name(const std::string &name);
bool is_valid_table_name(const std::string &value); bool is_valid_table_name(const std::string &value);