]> Savannah Git Hosting - gnulib.git/commitdiff
readline: fix memory leak in replacement readline.
authorNick Bowler <nbowler@draconx.ca>
Wed, 31 May 2023 01:26:19 +0000 (21:26 -0400)
committerBruno Haible <bruno@clisp.org>
Sun, 4 Jun 2023 19:19:18 +0000 (21:19 +0200)
* lib/readline.c (readline): Free memory after getline failure.
Copyright-paperwork-exempt: true

ChangeLog
lib/readline.c

index 06fd474a1a262d44322ebdb1c6f10c32c5c2ce1b..0ce7a07bb18554d4cb376d4c1035cc57ea2199b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-05-30  Nick Bowler  <nbowler@draconx.ca>
+
+       readline: fix memory leak in replacement readline.
+       * lib/readline.c (readline): Free memory after getline failure.
+       Copyright-paperwork-exempt: Yes
+
 2023-05-24  Bruno Haible  <bruno@clisp.org>
 
        asyncsafe-spin, simple-atomic: Don't use -mcpu-v9 on NetBSD/sparc.
index 56d5a9ee80491c4b560470ff5c2a2a5f412cf9a3..c307953266b6c47198ac76887f7855cc7d5618e8 100644 (file)
@@ -1,5 +1,5 @@
 /* readline.c --- Simple implementation of readline.
-   Copyright (C) 2005-2007, 2009-2022 Free Software Foundation, Inc.
+   Copyright (C) 2005-2007, 2009-2023 Free Software Foundation, Inc.
    Written by Simon Josefsson
 
    This program is free software: you can redistribute it and/or modify
@@ -30,6 +30,7 @@
 #include "readline.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 char *
@@ -45,7 +46,10 @@ readline (const char *prompt)
     }
 
   if (getline (&out, &size, stdin) < 0)
-    return NULL;
+    {
+      free (out);
+      return NULL;
+    }
 
   while (*out && (out[strlen (out) - 1] == '\r'
                   || out[strlen (out) - 1] == '\n'))