poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fix a small memory leak


From: Jose E. Marchesi
Subject: Re: fix a small memory leak
Date: Sun, 28 Jun 2020 12:15:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Bruno.

    'line' is being free()ed when it is non-empty but not when it is empty.
    This is the kind of bugs that convinced me to avoid 'continue' statements
    and prefer plain 'if' instead.

Yeah I agree regarding continue vs. if.
This is OK for master, thanks.

    
    >From 1199b756b8a5531dccdaa047c881df1db2440cde Mon Sep 17 00:00:00 2001
    From: Bruno Haible <bruno@clisp.org>
    Date: Sat, 27 Jun 2020 16:08:45 +0200
    Subject: [PATCH] Fix a small memory leak.
    
    * poke/pk-repl.c (pk_repl): Free the line also when it is empty.
    ---
     poke/pk-repl.c | 10 +++++-----
     1 file changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/poke/pk-repl.c b/poke/pk-repl.c
    index d0b3d7a..08505cb 100644
    --- a/poke/pk-repl.c
    +++ b/poke/pk-repl.c
    @@ -329,14 +329,14 @@ pk_repl (void)
             }
     
           /* Ignore empty lines.  */
    -      if (*line == '\0')
    -        continue;
    -
    +      if (*line != '\0')
    +        {
     #if defined HAVE_READLINE_HISTORY_H
    -      add_history (line);
    +          add_history (line);
     #endif
     
    -      pk_cmd_exec (line);
    +          pk_cmd_exec (line);
    +        }
           free (line);
         }
     #if defined HAVE_READLINE_HISTORY_H



reply via email to

[Prev in Thread] Current Thread [Next in Thread]