aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-27 10:17:16 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-27 10:17:16 +0000
commit86b29ea9e8d14436fde48fedf2896ae679201266 (patch)
tree985b0acfb1736428b9f444570eddfdbe143ac180 /libbb/lineedit.c
parent33b900f984e7397c4143c580eef9c8930677a9e2 (diff)
downloadbusybox-w32-86b29ea9e8d14436fde48fedf2896ae679201266.tar.gz
busybox-w32-86b29ea9e8d14436fde48fedf2896ae679201266.tar.bz2
busybox-w32-86b29ea9e8d14436fde48fedf2896ae679201266.zip
lineedit: plug memory leak
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index a018a53ff..a66398a95 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -81,8 +81,9 @@ static int num_ok_lines = 1;
81#endif 81#endif
82 82
83#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR 83#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
84static char *user_buf = (char*)""; 84static const char null_str[] = "";
85static char *home_pwd_buf = (char*)""; 85static char *user_buf;
86static char *home_pwd_buf = (char*)null_str;
86#endif 87#endif
87 88
88/* Put 'command_ps[cursor]', cursor++. 89/* Put 'command_ps[cursor]', cursor++.
@@ -311,7 +312,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
311 312
312 if (with_shash_flg) { /* "~/..." or "~user/..." */ 313 if (with_shash_flg) { /* "~/..." or "~user/..." */
313 char *sav_ud = ud - 1; 314 char *sav_ud = ud - 1;
314 char *home = 0; 315 char *home = NULL;
315 char *temp; 316 char *temp;
316 317
317 if (*ud == '/') { /* "~/..." */ 318 if (*ud == '/') { /* "~/..." */
@@ -1119,7 +1120,7 @@ static void parse_prompt(const char *prmt_ptr)
1119 switch (c) { 1120 switch (c) {
1120#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR 1121#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
1121 case 'u': 1122 case 'u':
1122 pbuf = user_buf; 1123 pbuf = user_buf ? user_buf : (char*)"";
1123 break; 1124 break;
1124#endif 1125#endif
1125 case 'h': 1126 case 'h':
@@ -1143,7 +1144,7 @@ static void parse_prompt(const char *prmt_ptr)
1143 case 'w': 1144 case 'w':
1144 pbuf = pwd_buf; 1145 pbuf = pwd_buf;
1145 l = strlen(home_pwd_buf); 1146 l = strlen(home_pwd_buf);
1146 if (home_pwd_buf[0] != 0 1147 if (l != 0
1147 && strncmp(home_pwd_buf, pbuf, l) == 0 1148 && strncmp(home_pwd_buf, pbuf, l) == 0
1148 && (pbuf[l]=='/' || pbuf[l]=='\0') 1149 && (pbuf[l]=='/' || pbuf[l]=='\0')
1149 && strlen(pwd_buf+l)<PATH_MAX 1150 && strlen(pwd_buf+l)<PATH_MAX
@@ -1310,8 +1311,14 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t
1310 1311
1311 entry = getpwuid(geteuid()); 1312 entry = getpwuid(geteuid());
1312 if (entry) { 1313 if (entry) {
1314 /* If we enter read_line_input for the Nth time,
1315 * they may be already allocated! Need to free. */
1316 free(user_buf);
1317 if (home_pwd_buf != null_str);
1318 free(home_pwd_buf);
1313 user_buf = xstrdup(entry->pw_name); 1319 user_buf = xstrdup(entry->pw_name);
1314 home_pwd_buf = xstrdup(entry->pw_dir); 1320 home_pwd_buf = xstrdup(entry->pw_dir);
1321 /* They are not freed on exit (too small to bother) */
1315 } 1322 }
1316 } 1323 }
1317#endif 1324#endif