From b8789d77988c4cf6359112e4b1340bc6bcb2d0f4 Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 10 Dec 2001 21:29:52 -0800 Subject: [PATCH] [svn] Fix obvious memory leaks in the VMS directory parser. Published in . --- src/ChangeLog | 4 ++++ src/ftp-ls.c | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6feff5c3..7c85fb59 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2001-12-11 Hrvoje Niksic + + * ftp-ls.c (ftp_parse_vms_ls): Fix obvious memory leaks. + 2001-12-10 Hrvoje Niksic * main.c (main): Initialize progress after fork_to_background, so diff --git a/src/ftp-ls.c b/src/ftp-ls.c index 4279c494..bf613b24 100644 --- a/src/ftp-ls.c +++ b/src/ftp-ls.c @@ -577,23 +577,31 @@ ftp_parse_vms_ls (const char *file) } dir = l = NULL; - /* #### The next three lines are a memory leak because they don't - bother to free the pointer that read_whole_line() returns! - FIXME! */ + /* Skip empty line. */ + line = read_whole_line (fp); + if (line) + xfree (line); - /* Empty line */ - read_whole_line (fp); - /* "Directory PUB$DEVICE[PUB]" */ - read_whole_line (fp); - /* Empty line */ - read_whole_line (fp); + /* Skip "Directory PUB$DEVICE[PUB]" */ + line = read_whole_line (fp); + if (line) + xfree (line); + + /* Skip empty line. */ + line = read_whole_line (fp); + if (line) + xfree (line); /* Line loop to end of file: */ while ((line = read_whole_line (fp))) { char *p; i = clean_line (line); - if (!i) break; + if (!i) + { + xfree (line); + break; + } /* First column: Name. A bit of black magic again. The name my be either ABCD.EXT or ABCD.EXT;NUM and it might be on a separate @@ -650,6 +658,7 @@ ftp_parse_vms_ls (const char *file) if (!i) { DEBUGP(("confusing VMS listing item, leaving listing parser\n")); + xfree (line); break; } tok = strtok(line, " "); @@ -669,6 +678,7 @@ ftp_parse_vms_ls (const char *file) the first strtok(NULL, "-") will return everything until the end of the line and only the next strtok() call will return NULL. */ DEBUGP(("nonsense in VMS listing, skipping this line\n")); + xfree (line); break; } for (i=0; i<12; i++) if (!strcmp(tok,months[i])) break; @@ -718,6 +728,7 @@ ftp_parse_vms_ls (const char *file) if (tok == NULL) { DEBUGP(("confusing VMS permissions, skipping line\n")); + xfree (line); continue; } /* Permissons have the format "RWED,RWED,RE" */ -- 2.39.2