mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 05:13:30 -07:00
WebUI: Fix memory leak
See #22734, there is a memory leak in the MooTools .destroy(), this replaces all uses of that with the browser native .remove(). This also overrides the MooTools Document.id function, which is used by $(id). The original function always allocates an ID to elements it selects, the override doesn't, and is also a little more efficient. Closes #22734. PR #22754. --------- Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
parent
1da31bc2e1
commit
535fc42747
10 changed files with 85 additions and 11 deletions
|
@ -26,6 +26,7 @@
|
||||||
<script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
|
<script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
|
||||||
<script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
|
<script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
|
||||||
<script defer src="scripts/lib/mocha.min.js"></script>
|
<script defer src="scripts/lib/mocha.min.js"></script>
|
||||||
|
<script defer src="scripts/monkeypatch.js?v=${CACHEID}"></script>
|
||||||
<script defer src="scripts/cache.js?v=${CACHEID}"></script>
|
<script defer src="scripts/cache.js?v=${CACHEID}"></script>
|
||||||
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
|
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
|
||||||
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
|
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
|
||||||
|
|
|
@ -499,7 +499,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
if (!categoryList)
|
if (!categoryList)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[...categoryList.children].forEach((el) => { el.destroy(); });
|
[...categoryList.children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
const categoryItemTemplate = document.getElementById("categoryFilterItem");
|
const categoryItemTemplate = document.getElementById("categoryFilterItem");
|
||||||
|
|
||||||
|
@ -620,7 +620,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
if (tagFilterList === null)
|
if (tagFilterList === null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[...tagFilterList.children].forEach((el) => { el.destroy(); });
|
[...tagFilterList.children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
const tagItemTemplate = document.getElementById("tagFilterItem");
|
const tagItemTemplate = document.getElementById("tagFilterItem");
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
|
||||||
if (trackerFilterList === null)
|
if (trackerFilterList === null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[...trackerFilterList.children].forEach((el) => { el.destroy(); });
|
[...trackerFilterList.children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
const trackerItemTemplate = document.getElementById("trackerFilterItem");
|
const trackerItemTemplate = document.getElementById("trackerFilterItem");
|
||||||
|
|
||||||
|
|
|
@ -478,7 +478,7 @@ window.qBittorrent.ContextMenu ??= (() => {
|
||||||
|
|
||||||
updateCategoriesSubMenu(categories) {
|
updateCategoriesSubMenu(categories) {
|
||||||
const contextCategoryList = $("contextCategoryList");
|
const contextCategoryList = $("contextCategoryList");
|
||||||
[...contextCategoryList.children].forEach((el) => { el.destroy(); });
|
[...contextCategoryList.children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
const createMenuItem = (text, imgURL, clickFn) => {
|
const createMenuItem = (text, imgURL, clickFn) => {
|
||||||
const anchor = document.createElement("a");
|
const anchor = document.createElement("a");
|
||||||
|
|
|
@ -907,14 +907,14 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||||
this.selectedRows.erase(rowId);
|
this.selectedRows.erase(rowId);
|
||||||
this.rows.delete(rowId);
|
this.rows.delete(rowId);
|
||||||
const tr = this.getTrByRowId(rowId);
|
const tr = this.getTrByRowId(rowId);
|
||||||
tr?.destroy();
|
tr?.remove();
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function() {
|
clear: function() {
|
||||||
this.deselectAll();
|
this.deselectAll();
|
||||||
this.rows.clear();
|
this.rows.clear();
|
||||||
for (const tr of this.getTrs())
|
for (const tr of this.getTrs())
|
||||||
tr.destroy();
|
tr.remove();
|
||||||
},
|
},
|
||||||
|
|
||||||
selectedRowsIds: function() {
|
selectedRowsIds: function() {
|
||||||
|
|
72
src/webui/www/private/scripts/monkeypatch.js
Normal file
72
src/webui/www/private/scripts/monkeypatch.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2025 bolshoytoster <toasterbig@gmail.com>
|
||||||
|
* Copyright (C) 2025 Mike Tzou (Chocobo1)
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give permission to
|
||||||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||||||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||||||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||||
|
* exception statement from your version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
window.qBittorrent ??= {};
|
||||||
|
window.qBittorrent.MonkeyPatch ??= (() => {
|
||||||
|
const exports = () => {
|
||||||
|
return {
|
||||||
|
patch: patch
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const patch = () => {
|
||||||
|
patchMootoolsDocumentId();
|
||||||
|
};
|
||||||
|
|
||||||
|
const patchMootoolsDocumentId = () => {
|
||||||
|
// Override MooTools' `document.id` (used for `$(id)`), which prevents it
|
||||||
|
// from allocating a `uniqueNumber` for elements that don't need it.
|
||||||
|
// MooTools and MochaUI use it internally.
|
||||||
|
|
||||||
|
if (document.id === undefined)
|
||||||
|
return;
|
||||||
|
|
||||||
|
document.id = (el) => {
|
||||||
|
if ((el === null) || (el === undefined))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
switch (typeof el) {
|
||||||
|
case "object":
|
||||||
|
return el;
|
||||||
|
case "string":
|
||||||
|
return document.getElementById(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return exports();
|
||||||
|
})();
|
||||||
|
Object.freeze(window.qBittorrent.MonkeyPatch);
|
||||||
|
|
||||||
|
// execute now
|
||||||
|
window.qBittorrent.MonkeyPatch.patch();
|
|
@ -248,7 +248,7 @@ window.qBittorrent.Search ??= (() => {
|
||||||
if (state && state.running)
|
if (state && state.running)
|
||||||
stopSearch(searchId);
|
stopSearch(searchId);
|
||||||
|
|
||||||
tab.destroy();
|
tab.remove();
|
||||||
|
|
||||||
fetch("api/v2/search/delete", {
|
fetch("api/v2/search/delete", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteCookie = (element) => {
|
const deleteCookie = (element) => {
|
||||||
element.closest("tr").destroy();
|
element.closest("tr").remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
|
|
|
@ -2110,7 +2110,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
||||||
|
|
||||||
// Advanced Tab
|
// Advanced Tab
|
||||||
const updateNetworkInterfaces = (default_iface, default_iface_name) => {
|
const updateNetworkInterfaces = (default_iface, default_iface_name) => {
|
||||||
[...document.getElementById("networkInterface").children].forEach((el) => { el.destroy(); });
|
[...document.getElementById("networkInterface").children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
fetch("api/v2/app/networkInterfaceList", {
|
fetch("api/v2/app/networkInterfaceList", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
@ -2139,7 +2139,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateInterfaceAddresses = (iface, default_addr) => {
|
const updateInterfaceAddresses = (iface, default_addr) => {
|
||||||
[...document.getElementById("optionalIPAddressToBind").children].forEach((el) => { el.destroy(); });
|
[...document.getElementById("optionalIPAddressToBind").children].forEach((el) => { el.remove(); });
|
||||||
|
|
||||||
const url = new URL("api/v2/app/networkInterfaceAddressList", window.location);
|
const url = new URL("api/v2/app/networkInterfaceAddressList", window.location);
|
||||||
url.search = new URLSearchParams({
|
url.search = new URLSearchParams({
|
||||||
|
|
|
@ -422,7 +422,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearDetails = () => {
|
const clearDetails = () => {
|
||||||
[...document.getElementById("rssDetailsView").children].forEach((el) => { el.destroy(); });
|
[...document.getElementById("rssDetailsView").children].forEach((el) => { el.remove(); });
|
||||||
};
|
};
|
||||||
|
|
||||||
const showDetails = (feedUid, articleID) => {
|
const showDetails = (feedUid, articleID) => {
|
||||||
|
|
|
@ -407,6 +407,7 @@
|
||||||
<file>private/scripts/localpreferences.js</file>
|
<file>private/scripts/localpreferences.js</file>
|
||||||
<file>private/scripts/misc.js</file>
|
<file>private/scripts/misc.js</file>
|
||||||
<file>private/scripts/mocha-init.js</file>
|
<file>private/scripts/mocha-init.js</file>
|
||||||
|
<file>private/scripts/monkeypatch.js</file>
|
||||||
<file>private/scripts/pathAutofill.js</file>
|
<file>private/scripts/pathAutofill.js</file>
|
||||||
<file>private/scripts/piecesbar.js</file>
|
<file>private/scripts/piecesbar.js</file>
|
||||||
<file>private/scripts/progressbar.js</file>
|
<file>private/scripts/progressbar.js</file>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue