mg(1) does not close DIR on error path

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mg(1) does not close DIR on error path

Igor Zinovik-3
        Hello.

mg(1) editor has a small resource leak in make_file_list() function.
If it cannot allocate space for `current' list it returns without
closing `dirp' with closedir() call.

Index: fileio.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/fileio.c,v
retrieving revision 1.84
diff -U 3 -p -r1.84 fileio.c
--- fileio.c 21 Jan 2011 19:10:13 -0000 1.84
+++ fileio.c 18 Mar 2011 19:55:18 -0000
@@ -551,6 +551,7 @@ make_file_list(char *buf)
 
  if ((current = malloc(sizeof(struct list))) == NULL) {
  free_file_list(last);
+ closedir(dirp);
  return (NULL);
  }
  ret = snprintf(fl_name, sizeof(fl_name),

Reply | Threaded
Open this post in threaded view
|

Re: mg(1) does not close DIR on error path

Mark Lumsden-2
>       Hello.
>
> mg(1) editor has a small resource leak in make_file_list() function.
> If it cannot allocate space for `current' list it returns without
> closing `dirp' with closedir() call.
>
> Index: fileio.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mg/fileio.c,v
> retrieving revision 1.84
> diff -U 3 -p -r1.84 fileio.c
> --- fileio.c  21 Jan 2011 19:10:13 -0000      1.84
> +++ fileio.c  18 Mar 2011 19:55:18 -0000
> @@ -551,6 +551,7 @@ make_file_list(char *buf)
>
>               if ((current = malloc(sizeof(struct list))) == NULL) {
>                       free_file_list(last);
> +                     closedir(dirp);
>                       return (NULL);
>               }
>               ret = snprintf(fl_name, sizeof(fl_name),

Looks good to me. Thanks.

-lum