Fixes leaks such as:
Direct leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x7eff58beb850 in malloc (/lib64/libasan.so.4+0xde850)
    #1 0x7eff57942f0c in g_malloc ../glib/gmem.c:94
    #2 0x7eff579431cf in g_malloc_n ../glib/gmem.c:331
    #3 0x7eff5795f6eb in g_strdup ../glib/gstrfuncs.c:363
    #4 0x55db720f1d46 in readline_hist_add /home/elmarco/src/qq/util/readline.c:258
    #5 0x55db720f2d34 in readline_handle_byte /home/elmarco/src/qq/util/readline.c:387
    #6 0x55db71539d00 in monitor_read /home/elmarco/src/qq/monitor.c:3896
    #7 0x55db71f9be35 in qemu_chr_be_write_impl /home/elmarco/src/qq/chardev/char.c:167
    #8 0x55db71f9bed3 in qemu_chr_be_write /home/elmarco/src/qq/chardev/char.c:179
    #9 0x55db71fa013c in fd_chr_read /home/elmarco/src/qq/chardev/char-fd.c:66
    #10 0x55db71fe18a8 in qio_channel_fd_source_dispatch /home/elmarco/src/qq/io/channel-watch.c:84
    #11 0x7eff5793a90b in g_main_dispatch ../glib/gmain.c:3182
    #12 0x7eff5793b7ac in g_main_context_dispatch ../glib/gmain.c:3847
    #13 0x55db720af3bd in glib_pollfds_poll /home/elmarco/src/qq/util/main-loop.c:214
    #14 0x55db720af505 in os_host_main_loop_wait /home/elmarco/src/qq/util/main-loop.c:261
    #15 0x55db720af6d6 in main_loop_wait /home/elmarco/src/qq/util/main-loop.c:515
    #16 0x55db7184e0de in main_loop /home/elmarco/src/qq/vl.c:1995
    #17 0x55db7185e956 in main /home/elmarco/src/qq/vl.c:4914
    #18 0x7eff4ea17039 in __libc_start_main (/lib64/libc.so.6+0x21039)
(while at it, use g_new0(ReadLineState), it's a bit easier to read)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180104160523.22995-11-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
		
	
			
		
			
				
	
	
		
			65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#ifndef READLINE_H
 | 
						|
#define READLINE_H
 | 
						|
 | 
						|
#define READLINE_CMD_BUF_SIZE 4095
 | 
						|
#define READLINE_MAX_CMDS 64
 | 
						|
#define READLINE_MAX_COMPLETIONS 256
 | 
						|
 | 
						|
typedef void GCC_FMT_ATTR(2, 3) ReadLinePrintfFunc(void *opaque,
 | 
						|
                                                   const char *fmt, ...);
 | 
						|
typedef void ReadLineFlushFunc(void *opaque);
 | 
						|
typedef void ReadLineFunc(void *opaque, const char *str,
 | 
						|
                          void *readline_opaque);
 | 
						|
typedef void ReadLineCompletionFunc(void *opaque,
 | 
						|
                                    const char *cmdline);
 | 
						|
 | 
						|
typedef struct ReadLineState {
 | 
						|
    char cmd_buf[READLINE_CMD_BUF_SIZE + 1];
 | 
						|
    int cmd_buf_index;
 | 
						|
    int cmd_buf_size;
 | 
						|
 | 
						|
    char last_cmd_buf[READLINE_CMD_BUF_SIZE + 1];
 | 
						|
    int last_cmd_buf_index;
 | 
						|
    int last_cmd_buf_size;
 | 
						|
 | 
						|
    int esc_state;
 | 
						|
    int esc_param;
 | 
						|
 | 
						|
    char *history[READLINE_MAX_CMDS];
 | 
						|
    int hist_entry;
 | 
						|
 | 
						|
    ReadLineCompletionFunc *completion_finder;
 | 
						|
    char *completions[READLINE_MAX_COMPLETIONS];
 | 
						|
    int nb_completions;
 | 
						|
    int completion_index;
 | 
						|
 | 
						|
    ReadLineFunc *readline_func;
 | 
						|
    void *readline_opaque;
 | 
						|
    int read_password;
 | 
						|
    char prompt[256];
 | 
						|
 | 
						|
    ReadLinePrintfFunc *printf_func;
 | 
						|
    ReadLineFlushFunc *flush_func;
 | 
						|
    void *opaque;
 | 
						|
} ReadLineState;
 | 
						|
 | 
						|
void readline_add_completion(ReadLineState *rs, const char *str);
 | 
						|
void readline_set_completion_index(ReadLineState *rs, int completion_index);
 | 
						|
 | 
						|
const char *readline_get_history(ReadLineState *rs, unsigned int index);
 | 
						|
 | 
						|
void readline_handle_byte(ReadLineState *rs, int ch);
 | 
						|
 | 
						|
void readline_start(ReadLineState *rs, const char *prompt, int read_password,
 | 
						|
                    ReadLineFunc *readline_func, void *readline_opaque);
 | 
						|
void readline_restart(ReadLineState *rs);
 | 
						|
void readline_show_prompt(ReadLineState *rs);
 | 
						|
 | 
						|
ReadLineState *readline_init(ReadLinePrintfFunc *printf_func,
 | 
						|
                             ReadLineFlushFunc *flush_func,
 | 
						|
                             void *opaque,
 | 
						|
                             ReadLineCompletionFunc *completion_finder);
 | 
						|
void readline_free(ReadLineState *rs);
 | 
						|
 | 
						|
#endif /* READLINE_H */
 |