nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] splint finds memory-leaks in nano.c


From: Steven Kneizys
Subject: Re: [Nano-devel] splint finds memory-leaks in nano.c
Date: Sat, 2 Mar 2002 07:07:29 -0800 (PST)

I just did a spell check with replace, 'fixed' them and ened up with a
nearly identical diff file afterwards with the exception of an extra
free needed.

In files.c, there is a possible bug in check_writable_directory,
comment says it is full_path but path is used instead:

    /* otherwise, stat() the full path to see if it's writable by the
       user; set writable to 1 if it is, or 0 if it isn't */
    stat(path, &fileinfo);

There was unfreed memory from checking the writable directory too.

I am still getting the leaks from paths in the do_browser calls :)  I
will look at them sometime.

Steve...
--

diff -c files.c.old files.c
*** files.c.old Sat Mar  2 10:05:50 2002
--- files.c     Sat Mar  2 10:08:01 2002
***************
*** 1077,1083 ****

      /* otherwise, stat() the full path to see if it's writable by the
         user; set writable to 1 if it is, or 0 if it isn't */
!     stat(path, &fileinfo);
      if (fileinfo.st_mode & S_IWUSR)
        writable = 1;
      else
--- 1077,1083 ----

      /* otherwise, stat() the full path to see if it's writable by the
         user; set writable to 1 if it is, or 0 if it isn't */
!     stat(full_path, &fileinfo);
      if (fileinfo.st_mode & S_IWUSR)
        writable = 1;
      else
***************
*** 1168,1173 ****
--- 1168,1174 ----

      strcat(buf, "XXXXXX");
      filedesc = mkstemp(buf);
+     free(full_tempdir);

      /* if mkstemp() failed, get out */
      if (filedesc == -1)

diff -c nano.c.old nano.c
*** nano.c.old  Sat Feb 23 12:16:41 2002
--- nano.c      Sat Mar  2 09:46:03 2002
***************
*** 1509,1516 ****
      }

      /* restore the search/replace strings */
!     last_search = mallocstrcpy(last_search, save_search);
!     last_replace = mallocstrcpy(last_replace, save_replace);

      /* restore where we were */
      current = begin;
--- 1509,1519 ----
      }

      /* restore the search/replace strings */
!     free(last_search);
!     last_search = save_search;
!     free(last_replace);
!     last_replace = save_replace;
!     free(prevanswer);

      /* restore where we were */
      current = begin;
***************
*** 1739,1744 ****
--- 1742,1748 ----
      }

      if (write_file(temp, 1, 0, 0) == -1) {
+       free(temp);
        statusbar(_("Spell checking failed: unable to write temp
file!"));
        return 0;
      }
***************
*** 1757,1762 ****
--- 1761,1767 ----
        spell_res = do_int_speller(temp);

      remove(temp);
+     free(temp);

      if (spell_res)
        statusbar(_("Finished checking spelling"));

--- Rocco Corsi <address@hidden> wrote:
> I fixed a few obvious memory leaks in nano.c using report from
> splint.
> 
> Rocco
> > Index: nano.c
> ===================================================================
> RCS file: /cvsroot/nano/nano/nano.c,v
> retrieving revision 1.234
> diff -u -r1.234 nano.c
> --- nano.c    27 Feb 2002 04:14:16 -0000      1.234
> +++ nano.c    2 Mar 2002 07:40:09 -0000
> @@ -1516,8 +1516,9 @@
>      }
>  
>      /* restore the search/replace strings */
> -    last_search = mallocstrcpy(last_search, save_search);
> -    last_replace = mallocstrcpy(last_replace, save_replace);
> +    free(last_search);    last_search=save_search;
> +    free(last_replace);   last_replace=save_replace;
> +    free(prevanswer);
>  
>      /* restore where we were */
>      current = begin;
> @@ -1747,6 +1748,7 @@
>  
>      if (write_file(temp, 1, 0, 0) == -1) {
>       statusbar(_("Spell checking failed: unable to write temp file!"));
> +     free(temp);
>       return 0;
>      }
>  
> @@ -1769,6 +1771,7 @@
>      else
>       statusbar(_("Spell checking failed"));
>  
> +    free(temp);
>      return spell_res;
>  
>  #endif
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]