public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Plug memory leak in libgui/src/tkWinPrint*.c
@ 2001-08-03 14:41 Mo DeJong
  2001-08-03 14:44 ` PATCH: Fix compiler warning in src/tkWinPrintText.c Mo DeJong
  0 siblings, 1 reply; 6+ messages in thread
From: Mo DeJong @ 2001-08-03 14:41 UTC (permalink / raw)
  To: insight

Hi all.

I just added this patch. This code is not used by Insight
so there should be no need to worry about this change.

cheers
Mo

2001-08-02  Mo DeJong  <mdejong@redhat.com>

        * src/tkWinPrintCanvas.c (PrintCanvasCmd):
        * src/tkWinPrintText.c (PrintTextCmd): Plug
        memory leak by calling free on memory allocated
        in PrintCanvasCmd and PrintTextCmd method. Make
        sure error cases branch to the cleanup code at
        the end of the method instead of just returning.


Index: src/tkWinPrintCanvas.c
===================================================================
RCS file: /cvs/cvsfiles/devo/libgui/src/tkWinPrintCanvas.c,v
retrieving revision 1.4
diff -u -r1.4 tkWinPrintCanvas.c
--- tkWinPrintCanvas.c	1999/01/09 00:19:14	1.4
+++ tkWinPrintCanvas.c	2001/08/03 00:22:04
@@ -58,14 +58,14 @@
 	Tcl_AppendResult(interp, "wrong # args: should be \"",
 			 argv[0], " canvas \"",
 			 (char *) NULL);
-	return TCL_ERROR;
+	goto error;
     }
 
     /* The second arg is the canvas widget */
     if (!Tcl_GetCommandInfo(interp, argv[1], &canvCmd)) {
 	Tcl_AppendResult(interp, "couldn't get canvas information for \"",
 			 argv[1], "\"", (char *) NULL);
-	return TCL_ERROR;
+	goto error;
     }
     
     memset(&dm,0,sizeof(DEVMODE));
@@ -164,8 +164,12 @@
     EndDoc(pd.hDC);
 
 done:
+    free ((char*) lpdi->lpszDocName);
+    free (lpdi);
     return TCL_OK;
- error:
+error:
+    free ((char*) lpdi->lpszDocName);
+    free (lpdi);
     return TCL_ERROR;
 }
 
Index: src/tkWinPrintText.c
===================================================================
RCS file: /cvs/cvsfiles/devo/libgui/src/tkWinPrintText.c,v
retrieving revision 1.6.180.1
diff -u -r1.6.180.1 tkWinPrintText.c
--- tkWinPrintText.c	2001/08/02 21:56:44	1.6.180.1
+++ tkWinPrintText.c	2001/08/03 00:22:04
@@ -273,7 +273,7 @@
 	Tcl_AppendResult(interp, "wrong # args: should be \"",
 			 argv[0], " text \"",
 			 (char *) NULL);
-	return TCL_ERROR;
+	goto error;
     }
 
     /*
@@ -282,7 +282,7 @@
     if (!Tcl_GetCommandInfo(interp, argv[1], &textCmd)) {
 	Tcl_AppendResult(interp, "couldn't get text information for \"",
 			 argv[1], "\"", (char *) NULL);
-	return TCL_ERROR;
+	goto error;
     }
     
     memset(&dm,0,sizeof(DEVMODE));
@@ -446,8 +446,12 @@
     textPtr->dInfoPtr->flags|=DINFO_OUT_OF_DATE;
 
 done:
+    free ((char*) lpdi->lpszDocName);
+    free (lpdi);
     return TCL_OK;
- error:
+error:
+    free ((char*) lpdi->lpszDocName);
+    free (lpdi);
     return TCL_ERROR;
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Fix compiler warning in src/tkWinPrintText.c
  2001-08-03 14:41 PATCH: Plug memory leak in libgui/src/tkWinPrint*.c Mo DeJong
@ 2001-08-03 14:44 ` Mo DeJong
  2001-08-03 14:50   ` PATCH: Remove strdup use in libgui Mo DeJong
  0 siblings, 1 reply; 6+ messages in thread
From: Mo DeJong @ 2001-08-03 14:44 UTC (permalink / raw)
  To: insight

Hi all.

I just checked in this minor fixup for libgui.

cheers
Mo

2001-08-02  Mo DeJong  <mdejong@redhat.com>

        * src/tkWinPrintText.c (DisplayDLineToDrawable): Fix
        compiler warning by adding missing static modifier
        to funciton declaration.

Index: tkWinPrintText.c
===================================================================
RCS file: /cvs/src/src/libgui/src/tkWinPrintText.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- tkWinPrintText.c    2000/02/07 00:19:47     1.1
+++ tkWinPrintText.c    2001/08/02 21:57:32     1.2
@@ -212,7 +212,8 @@
 
 
 
-void DisplayDLineToDrawable(TkText *textPtr, DLine *dlPtr, DLine *prevPtr, TkWinDrawable *drawable);
+static void
+DisplayDLineToDrawable(TkText *textPtr, DLine *dlPtr, DLine *prevPtr, 
TkWinDrawable *drawable);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Remove strdup use in libgui
  2001-08-03 14:44 ` PATCH: Fix compiler warning in src/tkWinPrintText.c Mo DeJong
@ 2001-08-03 14:50   ` Mo DeJong
  2001-08-03 14:52     ` PATCH: Plug memory leak in src/tclhelp.c Mo DeJong
  2001-08-03 15:26     ` PATCH: Remove strdup use in libgui Andrew Cagney
  0 siblings, 2 replies; 6+ messages in thread
From: Mo DeJong @ 2001-08-03 14:50 UTC (permalink / raw)
  To: insight

Hi all.

Here is a little change I checked into src/tclhelp.c that gets
rid of the last use of strcpy in libgui. This should not change
the functionality of any code in Insight.

cheers
Mo

2001-08-02  Mo DeJong  <mdejong@redhat.com>

	* config.h.in: Regen.
	* configure: Regen.
	* configure.in: Don't check for strdup since it
	is no longer used in libgui.
	* src/tclhelp.c (help_initialize_command): Replace
	use of strdup with calls to malloc and strcpy.

Index: configure.in
===================================================================
RCS file: /cvs/src/src/libgui/configure.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- configure.in        2001/04/10 20:08:25     1.3
+++ configure.in        2001/08/02 21:48:17     1.4
@@ -15,7 +15,7 @@
 
 AC_FUNC_ALLOCA
 AC_HAVE_HEADERS(stddef.h stdlib.h getopt.h unistd.h fcntl.h sys/file.h sys/wait.h string.h strings.h)
-AC_CHECK_FUNCS(raise strdup)
+AC_CHECK_FUNCS(raise)
 
 AC_ARG_ENABLE(ide, [  --enable-ide            Enable IDE support],
 [case "${enableval}" in
Index: tclhelp.c
===================================================================
RCS file: /cvs/src/src/libgui/src/tclhelp.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- tclhelp.c   2001/08/02 21:12:52     1.2
+++ tclhelp.c   2001/08/02 21:48:17     1.3
@@ -223,8 +223,10 @@
 {
   struct help_command_data *hdata = (struct help_command_data *) cd;
 
-  hdata->filename = strdup (argv[2]);
-  hdata->header_filename = strdup (argv[3]);
+  hdata->filename = malloc (strlen (argv[2]) + 1);
+  strcpy (hdata->filename, argv[2]);
+  hdata->header_filename = malloc (strlen (argv[3]) + 1);
+  strcpy (hdata->header_filename, argv[3]);
   return TCL_OK;
 }
 
@@ -407,9 +409,12 @@
 {
   struct help_command_data *hdata = (struct help_command_data *) cd;
 
-  hdata->filename = strdup (argv[2]);
-  hdata->header_filename = strdup (argv[3]);
-  hdata->help_dir = strdup (argv[4]);
+  hdata->filename = malloc (strlen (argv[2]) + 1);
+  strcpy (hdata->filename, argv[2]);
+  hdata->header_filename = malloc (strlen (argv[3]) + 1);
+  strcpy (hdata->header_filename, argv[3]);
+  hdata->help_dir = malloc (strlen (argv[4]) + 1);
+  strcpy (hdata->help_dir, argv[4]);
   return TCL_OK;
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* PATCH: Plug memory leak in src/tclhelp.c
  2001-08-03 14:50   ` PATCH: Remove strdup use in libgui Mo DeJong
@ 2001-08-03 14:52     ` Mo DeJong
  2001-08-03 15:26     ` PATCH: Remove strdup use in libgui Andrew Cagney
  1 sibling, 0 replies; 6+ messages in thread
From: Mo DeJong @ 2001-08-03 14:52 UTC (permalink / raw)
  To: insight

Hi all.

I checked in this little patch to fix a memory leak in
src/tclhelp.c.

cheers
Mo

2001-08-02  Mo DeJong  <mdejong@redhat.com>

	* src/tclhelp.c (help_command_deleted): Free the
	help_command_data->help_dir member allocated in
	help_initialize_command.

Index: tclhelp.c
===================================================================
RCS file: /cvs/src/src/libgui/src/tclhelp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- tclhelp.c   2000/02/07 00:19:47     1.1
+++ tclhelp.c   2001/08/02 21:12:52     1.2
@@ -390,6 +390,8 @@
     free (hdata->filename);
   if (hdata->header_filename != NULL)
     free (hdata->header_filename);
+  if (hdata->help_dir != NULL)
+    free (hdata->help_dir);
   if (hdata->hash_initialized)
     Tcl_DeleteHashTable (&hdata->topic_hash);
   if (hdata->memory_block != NULL)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Remove strdup use in libgui
  2001-08-03 14:50   ` PATCH: Remove strdup use in libgui Mo DeJong
  2001-08-03 14:52     ` PATCH: Plug memory leak in src/tclhelp.c Mo DeJong
@ 2001-08-03 15:26     ` Andrew Cagney
  2001-08-03 15:38       ` Mo DeJong
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2001-08-03 15:26 UTC (permalink / raw)
  To: Mo DeJong; +Cc: insight

> -  hdata->filename = strdup (argv[2]);
> -  hdata->header_filename = strdup (argv[3]);
> +  hdata->filename = malloc (strlen (argv[2]) + 1);
> +  strcpy (hdata->filename, argv[2]);
> +  hdata->header_filename = malloc (strlen (argv[3]) + 1);
> +  strcpy (hdata->header_filename, argv[3]);
>    return TCL_OK;


Mo, I'm puzzled.  Why do this?  What is wrong with strdup()?
	Andrew



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Remove strdup use in libgui
  2001-08-03 15:26     ` PATCH: Remove strdup use in libgui Andrew Cagney
@ 2001-08-03 15:38       ` Mo DeJong
  0 siblings, 0 replies; 6+ messages in thread
From: Mo DeJong @ 2001-08-03 15:38 UTC (permalink / raw)
  To: insight

On Fri, 3 Aug 2001, Andrew Cagney wrote:

> > -  hdata->filename = strdup (argv[2]);
> > -  hdata->header_filename = strdup (argv[3]);
> > +  hdata->filename = malloc (strlen (argv[2]) + 1);
> > +  strcpy (hdata->filename, argv[2]);
> > +  hdata->header_filename = malloc (strlen (argv[3]) + 1);
> > +  strcpy (hdata->header_filename, argv[3]);
> >    return TCL_OK;
> 
> 
> Mo, I'm puzzled.  Why do this?  What is wrong with strdup()?
> 	Andrew

This patch should shed some light on things (I am going
to post it in a minute). The strdup method uses malloc
while everything in libgui should make use of ckalloc/ckfree
so we can take advantage of TCL_MEM_DEBUG support.

cheers
Mo

Index: src/tclhelp.c
===================================================================
RCS file: /cvs/cvsfiles/devo/libgui/src/tclhelp.c,v
retrieving revision 1.6.212.2
diff -u -r1.6.212.2 tclhelp.c
--- tclhelp.c	2001/08/02 21:45:03	1.6.212.2
+++ tclhelp.c	2001/08/03 22:06:13
@@ -109,12 +109,12 @@
   Tcl_DeleteExitHandler (help_command_atexit, cd);
 
   if (hdata->filename != NULL)
-    free (hdata->filename);
+    ckfree (hdata->filename);
   if (hdata->header_filename != NULL)
-    free (hdata->header_filename);
+    ckfree (hdata->header_filename);
   if (hdata->hash_initialized)
     Tcl_DeleteHashTable (&hdata->topic_hash);
-  Tcl_Free ((char *) hdata);
+  ckfree ((char *) hdata);
 }
 
 /* Initialize the help system: choose a window, and set up the topic
@@ -223,9 +223,9 @@
 {
   struct help_command_data *hdata = (struct help_command_data *) cd;
 
-  hdata->filename = malloc (strlen (argv[2]) + 1);
+  hdata->filename = ckalloc (strlen (argv[2]) + 1);
   strcpy (hdata->filename, argv[2]);
-  hdata->header_filename = malloc (strlen (argv[3]) + 1);
+  hdata->header_filename = ckalloc (strlen (argv[3]) + 1);
   strcpy (hdata->header_filename, argv[3]);
   return TCL_OK;
 }
@@ -348,7 +348,7 @@
 {
   struct help_command_data *hdata;
 
-  hdata = (struct help_command_data *) Tcl_Alloc (sizeof *hdata);
+  hdata = (struct help_command_data *) ckalloc (sizeof *hdata);
 
   hdata->filename = NULL;
   hdata->header_filename = NULL;
@@ -389,16 +389,16 @@
   struct help_command_data *hdata = (struct help_command_data *) cd;
 
   if (hdata->filename != NULL)
-    free (hdata->filename);
+    ckfree (hdata->filename);
   if (hdata->header_filename != NULL)
-    free (hdata->header_filename);
+    ckfree (hdata->header_filename);
   if (hdata->help_dir != NULL)
-    free (hdata->help_dir);
+    ckfree (hdata->help_dir);
   if (hdata->hash_initialized)
     Tcl_DeleteHashTable (&hdata->topic_hash);
   if (hdata->memory_block != NULL)
-    free (hdata->memory_block);
-  Tcl_Free ((char *) hdata);
+    ckfree (hdata->memory_block);
+  ckfree ((char *) hdata);
 }
 
 /* Implement the ide_help initialize command.  */
@@ -409,11 +409,11 @@
 {
   struct help_command_data *hdata = (struct help_command_data *) cd;
 
-  hdata->filename = malloc (strlen (argv[2]) + 1);
+  hdata->filename = ckalloc (strlen (argv[2]) + 1);
   strcpy (hdata->filename, argv[2]);
-  hdata->header_filename = malloc (strlen (argv[3]) + 1);
+  hdata->header_filename = ckalloc (strlen (argv[3]) + 1);
   strcpy (hdata->header_filename, argv[3]);
-  hdata->help_dir = malloc (strlen (argv[4]) + 1);
+  hdata->help_dir = ckalloc (strlen (argv[4]) + 1);
   strcpy (hdata->help_dir, argv[4]);
   return TCL_OK;
 }
@@ -434,7 +434,7 @@
       FILE *e;
       char buf[200], *block_start;
 
-      block_start = hdata->memory_block = malloc(6000);
+      block_start = hdata->memory_block = ckalloc(6000);
 
       e = fopen (hdata->header_filename, "r");
       if (e == NULL)
@@ -567,7 +567,7 @@
 {
   struct help_command_data *hdata;
 
-  hdata = (struct help_command_data *) Tcl_Alloc (sizeof *hdata);
+  hdata = (struct help_command_data *) ckalloc (sizeof *hdata);
 
   hdata->filename = NULL;
   hdata->help_dir = NULL;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-08-03 15:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-03 14:41 PATCH: Plug memory leak in libgui/src/tkWinPrint*.c Mo DeJong
2001-08-03 14:44 ` PATCH: Fix compiler warning in src/tkWinPrintText.c Mo DeJong
2001-08-03 14:50   ` PATCH: Remove strdup use in libgui Mo DeJong
2001-08-03 14:52     ` PATCH: Plug memory leak in src/tclhelp.c Mo DeJong
2001-08-03 15:26     ` PATCH: Remove strdup use in libgui Andrew Cagney
2001-08-03 15:38       ` Mo DeJong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).