[Top][All Lists]

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

Memory leak in read_history_range when history file size is zero

From: Eduardo Bustamante
Subject: Memory leak in read_history_range when history file size is zero
Date: Thu, 27 Apr 2017 07:23:54 -0500

address@hidden:~/src/gnu/bash$ ./bash --noprofile --norc -ic
'HISTFILE=/dev/null; history -r'

==24289==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 10 byte(s) in 1 object(s) allocated from:
    #0 0x7efe83383d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
    #1 0x55a42abc3195 in xmalloc /home/dualbus/src/gnu/bash/xmalloc.c:112
    #2 0x55a42ac8b2c2 in history_filename
    #3 0x55a42ac8bc5a in read_history_range
    #4 0x55a42ac8bb7e in read_history
    #5 0x55a42abdd23a in history_builtin history.def:273
    #6 0x55a42aafd72b in execute_builtin
    #7 0x55a42aaff341 in execute_builtin_or_function
    #8 0x55a42aafcbc1 in execute_simple_command
    #9 0x55a42aaeaac2 in execute_command_internal
    #10 0x55a42aaf33ac in execute_connection
    #11 0x55a42aaeb897 in execute_command_internal
    #12 0x55a42abd44ae in parse_and_execute
    #13 0x55a42aab6121 in run_one_command
    #14 0x55a42aab45fa in main /home/dualbus/src/gnu/bash/shell.c:718
    #15 0x7efe82b162b0 in __libc_start_main

SUMMARY: AddressSanitizer: 10 byte(s) leaked in 1 allocation(s).


address@hidden:~/src/gnu/bash$ git diff -- lib/readline/histfile.c
diff --git a/lib/readline/histfile.c b/lib/readline/histfile.c
index 489801b4..66a76118 100644
--- a/lib/readline/histfile.c
+++ b/lib/readline/histfile.c
@@ -292,8 +292,10 @@ read_history_range (const char *filename, int from, int to)
       goto error_and_exit;

-  if (file_size == 0)
+  if (file_size == 0) {
+    FREE (input);
     return 0;  /* don't waste time if we don't have to */
+  }

   /* We map read/write and private so we can change newlines to NULs without

reply via email to

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