summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorRummskartoffel <Rummskartoffel@protonmail.com>2022-01-24 21:30:06 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-24 21:57:58 +0000
commitf3341f48e30051aa8bd38f744816e9b09fd88e35 (patch)
tree84781fe5df032fdc33cd22ab2eedd7c12d334451 /Userland
parentfa3c61cf5a31a7213d6efd078bac9bb438b5505b (diff)
downloadserenity-f3341f48e30051aa8bd38f744816e9b09fd88e35.zip
less: Fix memory leak when scrolling to EOF
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/less.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Utilities/less.cpp b/Userland/Utilities/less.cpp
index 1973a5c039..ae8c40213d 100644
--- a/Userland/Utilities/less.cpp
+++ b/Userland/Utilities/less.cpp
@@ -287,6 +287,9 @@ public:
char* line = nullptr;
size_t n = 0;
ssize_t size = getline(&line, &n, m_file);
+ ScopeGuard guard([line] {
+ free(line);
+ });
if (size == -1)
return false;
@@ -296,7 +299,6 @@ public:
--size;
m_lines.append(String(line, size));
- free(line);
return true;
}