Fix memleak on event creation due to not freeing storage object
This commit is contained in:
parent
721769993b
commit
6cd1f6b5f3
|
@ -103,7 +103,7 @@ Event::Event(
|
||||||
|
|
||||||
// Copy it in case opening the mp4 doesn't work we can set it to another value
|
// Copy it in case opening the mp4 doesn't work we can set it to another value
|
||||||
save_jpegs = monitor->GetOptSaveJPEGs();
|
save_jpegs = monitor->GetOptSaveJPEGs();
|
||||||
Storage * storage = monitor->getStorage();
|
Storage *storage = monitor->getStorage();
|
||||||
if (monitor->GetOptVideoWriter() != 0) {
|
if (monitor->GetOptVideoWriter() != 0) {
|
||||||
container = monitor->OutputContainer();
|
container = monitor->OutputContainer();
|
||||||
if ( container == "auto" || container == "" ) {
|
if ( container == "auto" || container == "" ) {
|
||||||
|
@ -133,22 +133,22 @@ Event::Event(
|
||||||
);
|
);
|
||||||
id = zmDbDoInsert(sql);
|
id = zmDbDoInsert(sql);
|
||||||
|
|
||||||
if ( !SetPath(storage) ) {
|
if (!SetPath(storage)) {
|
||||||
// Try another
|
// Try another
|
||||||
Warning("Failed creating event dir at %s", storage->Path());
|
Warning("Failed creating event dir at %s", storage->Path());
|
||||||
|
|
||||||
sql = stringtf("SELECT `Id` FROM `Storage` WHERE `Id` != %u", storage->Id());
|
sql = stringtf("SELECT `Id` FROM `Storage` WHERE `Id` != %u", storage->Id());
|
||||||
if ( monitor->ServerId() )
|
if (monitor->ServerId())
|
||||||
sql += stringtf(" AND ServerId=%u", monitor->ServerId());
|
sql += stringtf(" AND ServerId=%u", monitor->ServerId());
|
||||||
|
|
||||||
Debug(1, "%s", sql.c_str());
|
delete storage;
|
||||||
storage = nullptr;
|
storage = nullptr;
|
||||||
|
|
||||||
MYSQL_RES *result = zmDbFetch(sql);
|
MYSQL_RES *result = zmDbFetch(sql);
|
||||||
if ( result ) {
|
if (result) {
|
||||||
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
|
for (int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++) {
|
||||||
storage = new Storage(atoi(dbrow[0]));
|
storage = new Storage(atoi(dbrow[0]));
|
||||||
if ( SetPath(storage) )
|
if (SetPath(storage))
|
||||||
break;
|
break;
|
||||||
delete storage;
|
delete storage;
|
||||||
storage = nullptr;
|
storage = nullptr;
|
||||||
|
@ -156,18 +156,18 @@ Event::Event(
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
result = nullptr;
|
result = nullptr;
|
||||||
}
|
}
|
||||||
if ( !storage ) {
|
if (!storage) {
|
||||||
Info("No valid local storage area found. Trying all other areas.");
|
Info("No valid local storage area found. Trying all other areas.");
|
||||||
// Try remote
|
// Try remote
|
||||||
sql = "SELECT `Id` FROM `Storage` WHERE ServerId IS NULL";
|
sql = "SELECT `Id` FROM `Storage` WHERE ServerId IS NULL";
|
||||||
if ( monitor->ServerId() )
|
if (monitor->ServerId())
|
||||||
sql += stringtf(" OR ServerId != %u", monitor->ServerId());
|
sql += stringtf(" OR ServerId != %u", monitor->ServerId());
|
||||||
|
|
||||||
result = zmDbFetch(sql);
|
result = zmDbFetch(sql);
|
||||||
if ( result ) {
|
if (result) {
|
||||||
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
|
for ( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row(result); i++ ) {
|
||||||
storage = new Storage(atoi(dbrow[0]));
|
storage = new Storage(atoi(dbrow[0]));
|
||||||
if ( SetPath(storage) )
|
if (SetPath(storage))
|
||||||
break;
|
break;
|
||||||
delete storage;
|
delete storage;
|
||||||
storage = nullptr;
|
storage = nullptr;
|
||||||
|
@ -176,7 +176,7 @@ Event::Event(
|
||||||
result = nullptr;
|
result = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !storage ) {
|
if (!storage) {
|
||||||
storage = new Storage();
|
storage = new Storage();
|
||||||
Warning("Failed to find a storage area to save events.");
|
Warning("Failed to find a storage area to save events.");
|
||||||
}
|
}
|
||||||
|
@ -218,6 +218,7 @@ Event::Event(
|
||||||
Debug(1, "Video file is %s", video_file.c_str());
|
Debug(1, "Video file is %s", video_file.c_str());
|
||||||
}
|
}
|
||||||
} // end if GetOptVideoWriter
|
} // end if GetOptVideoWriter
|
||||||
|
delete storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::~Event() {
|
Event::~Event() {
|
||||||
|
|
Loading…
Reference in New Issue