]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: use static storage for vty_cwd
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 15 May 2019 22:42:41 +0000 (22:42 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 29 May 2019 18:03:26 +0000 (18:03 +0000)
Why are we allocating this

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/vty.c

index 9bee7b6c8317c86d88b2ec3b0fd26a3635f67ae9..2d97cca351bfacd76aa18af8dc2810b654c89261 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -84,7 +84,7 @@ static char *vty_ipv6_accesslist_name = NULL;
 static vector Vvty_serv_thread;
 
 /* Current directory. */
-char *vty_cwd = NULL;
+char vty_cwd[MAXPATHLEN];
 
 /* Login password check. */
 static int no_password_check = 0;
@@ -3056,10 +3056,9 @@ void vty_reset(void)
 
 static void vty_save_cwd(void)
 {
-       char cwd[MAXPATHLEN];
        char *c;
 
-       c = getcwd(cwd, MAXPATHLEN);
+       c = getcwd(vty_cwd, sizeof(vty_cwd));
 
        if (!c) {
                /*
@@ -3073,16 +3072,12 @@ static void vty_save_cwd(void)
                                     SYSCONFDIR, errno);
                        exit(-1);
                }
-               if (getcwd(cwd, MAXPATHLEN) == NULL) {
+               if (getcwd(vty_cwd, sizeof(vty_cwd)) == NULL) {
                        flog_err_sys(EC_LIB_SYSTEM_CALL,
                                     "Failure to getcwd, errno: %d", errno);
                        exit(-1);
                }
        }
-
-       size_t vty_cwd_sz = strlen(cwd) + 1;
-       vty_cwd = XMALLOC(MTYPE_TMP, vty_cwd_sz);
-       strlcpy(vty_cwd, cwd, vty_cwd_sz);
 }
 
 char *vty_get_cwd(void)
@@ -3148,7 +3143,7 @@ void vty_init(struct thread_master *master_thread)
 
 void vty_terminate(void)
 {
-       XFREE(MTYPE_TMP, vty_cwd);
+       memset(vty_cwd, 0x00, sizeof(vty_cwd));
 
        if (vtyvec && Vvty_serv_thread) {
                vty_reset();