delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/08/26/05:41:10

From: sos AT prospect DOT com DOT ru (Sergey Okhapkin)
Subject: Memory leaks in cygwin.dll
26 Aug 1998 05:41:10 -0700 :
Message-ID: <01BDD10C.34521810.cygnus.cygwin32.developers@sos>
To: "'cygwin32-developers AT cygnus DOT com'" <cygwin32-developers AT cygnus DOT com>

Hi!

include/sys/strace.h	(_STRACE_MALLOC, malloc_printf): define.

malloc.cc			(malloc, free, realloc, calloc): malloc_printf added.

path.cc			(getcwd_inner): do realloc instead of malloc.

syscalls.cc			(_close): delete unix_path_name_, because fhandler_base
				destructor is never called!

With these changes endless open/close loop runs without memory leaks.


--- strace.h.orig       Tue Apr 21 23:39:19 1998
+++ strace.h    Wed Aug 26 13:26:47 1998
@@ -46,6 +46,7 @@
 #define _STRACE_NEWFILE         0x1000 /* open a new file for strace */
 #define _STRACE_EXITDUMP 0x4000 /* dump strace cache on exit */
 #define _STRACE_CACHE   0x8000 /* cache strace messages */
+#define _STRACE_MALLOC 0x10000 /* trace malloc calls */

 /* Return the current strace mask.  */
 int strace (void);
@@ -72,6 +73,7 @@
 #define select_printf(fmt, args...) strace_printf_wrap(SELECT, fmt , ## args)
 #define wm_printf(fmt, args...) strace_printf_wrap(WM, fmt , ## args)
 #define sigproc_printf(fmt, args...) strace_printf_wrap(SIGP, fmt , ## args)
+#define malloc_printf(fmt, args...) strace_printf_wrap(MALLOC, fmt , ## args)

 #ifdef __cplusplus
 }

--- malloc.cc.orig      Fri May 29 14:18:09 1998
+++ malloc.cc   Wed Aug 26 13:54:01 1998
@@ -41,6 +41,7 @@ malloc (size_t size)
   in ("malloc");
   res = user_data->malloc (size);
   out ("malloc");
+  malloc_printf ("(%d) = %x, called by %x\n", size, res, ((int *)&size)[-1]);
   return res;
 }

@@ -49,6 +50,7 @@ free (void *p)
 {
   in ("free");
   user_data->free (p);
+  malloc_printf ("(%p), called by %x\n", p, ((int *)&p)[-1]);
   out ("free");
 }

@@ -59,6 +61,7 @@ realloc (void *p, size_t size)
   in ("realloc");
   res = user_data->realloc (p, size);
   out ("realloc");
+  malloc_printf ("(%x, %d) = %x, called by %x\n", p, size, res, ((int *)&p)[-1]);
   return res;
 }

@@ -69,6 +72,7 @@ calloc (size_t nmemb, size_t size)
   in ("calloc");
   res = user_data->calloc (nmemb, size);
   out ("calloc");
+  malloc_printf ("(%d, %d) = %x, called by %x\n", nmemb, size, res, ((int *)&nmemb)[-1]);
   return res;
 }


--- path.cc.orig        Sat Aug 15 22:31:56 1998
+++ path.cc     Wed Aug 26 16:04:26 1998
@@ -1242,7 +1242,8 @@ getcwd_inner (char *buf, size_t ulen, in

   size_t tlen = strlen (temp);

-  current_directory_posix_name = (char *) malloc (tlen + 1);
+  current_directory_posix_name = (char *) realloc (
+                                  current_directory_posix_name, tlen + 1);
   if (current_directory_posix_name != NULL)
     strcpy (current_directory_posix_name, temp);



--- syscalls.cc.orig    Wed Aug 26 15:49:21 1998
+++ syscalls.cc Wed Aug 26 15:47:04 1998
@@ -394,6 +394,7 @@ _close (int fd)
   else
     {
       res = myself->hmap[fd].h->close ();
+      delete [] myself->hmap[fd].h->get_name ();
       myself->hmap.release (fd);
     }
   syscall_printf ("%d = close (%d)\n", res, fd);

-- 
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019