mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
Userland: Don't leak buffer from getline in shuf program
Probably doesn't matter too too much since the program exits almost immediately after, but there's the principle of the thing to consider.
This commit is contained in:
parent
2930014c2a
commit
c2d8b8ec14
Notes:
sideshowbarker
2024-07-18 21:51:20 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/c2d8b8ec14d Pull-request: https://github.com/SerenityOS/serenity/pull/4921 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
1 changed files with 4 additions and 4 deletions
|
@ -40,12 +40,11 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
|
||||
Vector<String> lines;
|
||||
|
||||
char* buffer = nullptr;
|
||||
for (;;) {
|
||||
char* buffer = nullptr;
|
||||
ssize_t buflen = 0;
|
||||
size_t n;
|
||||
size_t n = 0;
|
||||
errno = 0;
|
||||
buflen = getline(&buffer, &n, stdin);
|
||||
ssize_t buflen = getline(&buffer, &n, stdin);
|
||||
if (buflen == -1 && errno != 0) {
|
||||
perror("getline");
|
||||
exit(1);
|
||||
|
@ -54,6 +53,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
break;
|
||||
lines.append({ buffer, AK::ShouldChomp::Chomp });
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
// Fisher-Yates shuffle
|
||||
String tmp;
|
||||
|
|
Loading…
Reference in a new issue