Finalize sub-queries to ensure we're not running out of memory with hundreds of clients (can result in O(N^2) memory requirements).

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-05-14 18:37:08 +02:00
parent 8c53844ef3
commit fe10059517
2 changed files with 5 additions and 0 deletions
+3
View File
@@ -69,17 +69,20 @@ if(isset($_GET["network"]) && $auth)
$network_addresses = $db->query("SELECT ip FROM network_addresses WHERE network_id = $id ORDER BY lastSeen DESC");
while($network_addresses !== false && $ip = $network_addresses->fetchArray(SQLITE3_ASSOC))
array_push($res["ip"],$ip["ip"]);
$network_addresses->finalize();
// Get list of host names for this device
$res["name"] = array();
$network_names = $db->query("SELECT name FROM network_names WHERE network_id = $id ORDER BY lastSeen DESC");
while($network_names !== false && $ip = $network_names->fetchArray(SQLITE3_ASSOC))
array_push($res["name"],utf8_encode($ip["name"]));
$network_names->finalize();
// UTF-8 encode vendor
$res["macVendor"] = utf8_encode($res["macVendor"]);
array_push($network, $res);
}
$results->finalize();
$data = array_merge($data, array('network' => $network));
}
+2
View File
@@ -194,6 +194,7 @@ if ($_POST['action'] == 'get_groups') {
while ($gres = $group_query->fetchArray(SQLITE3_ASSOC)) {
array_push($groups, $gres['group_id']);
}
$group_query->finalize();
$res['groups'] = $groups;
array_push($data, $res);
}
@@ -222,6 +223,7 @@ if ($_POST['action'] == 'get_groups') {
while ($res_names = $query_names->fetchArray(SQLITE3_ASSOC)) {
array_push($names, utf8_encode($res_names["name"]));
}
$query_names->finalize();
$extrainfo = "";
// Add device vendor to info string (if available)
if (strlen($res["macVendor"]) > 0) {