mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Fix memory leak in AuditLog::init()
This commit is contained in:
parent
8c549c65c4
commit
ec1112c648
@ -209,24 +209,36 @@ bool AuditLog::setType(AuditLogType audit_type) {
|
||||
|
||||
|
||||
bool AuditLog::init(std::string *error) {
|
||||
audit_log::writer::Writer *tmp_writer;
|
||||
|
||||
if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
|
||||
if (m_writer) {
|
||||
delete m_writer;
|
||||
m_writer = NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_type == ParallelAuditLogType) {
|
||||
m_writer = new audit_log::writer::Parallel(this);
|
||||
tmp_writer = new audit_log::writer::Parallel(this);
|
||||
} else if (m_type == HttpsAuditLogType) {
|
||||
m_writer = new audit_log::writer::Https(this);
|
||||
tmp_writer = new audit_log::writer::Https(this);
|
||||
} else {
|
||||
/*
|
||||
* if (m_type == SerialAuditLogType
|
||||
* || m_type == NotSetAuditLogType)
|
||||
*
|
||||
*/
|
||||
m_writer = new audit_log::writer::Serial(this);
|
||||
tmp_writer = new audit_log::writer::Serial(this);
|
||||
}
|
||||
|
||||
if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
|
||||
return true;
|
||||
if (tmp_writer == NULL) {
|
||||
error->assign("Writer memory alloc failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_writer == NULL || m_writer->init(error) == false) {
|
||||
if (tmp_writer->init(error) == false) {
|
||||
delete tmp_writer;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -245,6 +257,12 @@ bool AuditLog::init(std::string *error) {
|
||||
}
|
||||
}
|
||||
|
||||
if (m_writer) {
|
||||
delete m_writer;
|
||||
}
|
||||
|
||||
m_writer = tmp_writer;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user