src: use malloc() and free() from cli and main
Pablo Neira Ayuso
maintainerPATCH v2 1/3 src: use malloc() and free() from cli and main
xmalloc() and xfree() are internal symbols of the library, do not use them.
Fixes 16543a0136c0 ("libnftables: export public symbols only")
Reported-by Phil Sutter <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: exit() in case of OOM from cli
src/cli.c | 12 +++++++++--- src/main.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-)
src/cli.c +9 -3
@@ -63,9 +63,15 @@ static char *cli_append_multiline(char *line)rl_set_prompt (".... " ); }else { len +=strlen (multiline); - s =xmalloc (len +1 ); + s =malloc (len +1 ); +if (!s) { +fprintf (stderr,"%s:%u: Memory allocation failure\n" , + __FILE__, __LINE__); +cli_exit (); +exit (EXIT_FAILURE ); + }snprintf (s, len +1 ,"%s%s" , multiline, line); -xfree (multiline); +free (multiline); multiline = s; } line =NULL ;
@@ -111,7 +117,7 @@ static void cli_complete(char *line)add_history (line);nft_run_cmd_from_buffer (cli_nft, line); -xfree (line); +free (line); }static char **cli_completion (const char *text,int start,int end)
src/main.c +1 -1
@@ -329,7 +329,7 @@ int main(int argc, char * const *argv)exit (EXIT_FAILURE ); } -xfree (buf); +free (buf);nft_ctx_free (nft);return rc;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/3 main: replace NFT_EXIT_NOMEM by EXIT_FAILURE
The main.c file always uses either EXIT_FAILURE or EXIT_SUCCESS, replace this.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
src/main.c +1 -2
@@ -19,7 +19,6 @@#include <sys/types.h> #include <nftables/libnftables.h> -#include <nftables.h> #include <utils.h> #include <cli.h>
@@ -307,7 +306,7 @@ int main(int argc, char * const *argv)if (buf ==NULL ) {fprintf (stderr,"%s:%u: Memory allocation failure\n" , __FILE__, __LINE__); -exit (NFT_EXIT_NOMEM ); +exit (EXIT_FAILURE ); }for (i = optind; i < argc; i++) {strcat (buf, argv[i]);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/3 cli: remove useless #include headers
In reply to Pablo Neira AyusoSigned-off-by Pablo Neira Ayuso <[email protected]>
--- include/cli.h | 1 + src/cli.c | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-)
include/cli.h +1 -0
@@ -1,6 +1,7 @@#ifndef _NFT_CLI_H_#define _NFT_CLI_H_ +#include <nftables/libnftables.h> #include <config.h> struct parser_state ;
src/cli.c +1 -7
@@ -24,14 +24,8 @@#include <readline/readline.h> #include <readline/history.h> -#include <nftables.h> -#include <parser.h> -#include <erec.h> -#include <utils.h> -#include <iface.h> #include <cli.h> - -#include <libmnl/libmnl.h> +#include <list.h> #define CMDLINE_HISTFILE ".nft.history"
Signature · 1 line
2.11.0