Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] memory leak, mi-cmd-var
@ 2007-06-29  3:36 msnyder
  2007-06-29  4:32 ` Nick Roberts
  0 siblings, 1 reply; 3+ messages in thread
From: msnyder @ 2007-06-29  3:36 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 28 bytes --]

'nother one from Coverity.


[-- Attachment #2: formspec.txt --]
[-- Type: text/plain, Size: 1372 bytes --]

2007-06-28  Michael Snyder  <msnyder@access-company.com>

	* mi/mi-cmd-var.c (mi_cmd_var_set_format): Free strduped memory
	(Coverity).  Also take the opportunity to call error earlier
	(before strdup).

Index: mi/mi-cmd-var.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v
retrieving revision 1.33
diff -p -r1.33 mi-cmd-var.c
*** mi/mi-cmd-var.c	13 Jun 2007 19:08:47 -0000	1.33
--- mi/mi-cmd-var.c	29 Jun 2007 02:52:39 -0000
*************** mi_cmd_var_set_format (char *command, ch
*** 209,218 ****
    if (var == NULL)
      error (_("mi_cmd_var_set_format: Variable object not found"));
  
!   formspec = xstrdup (argv[1]);
!   if (formspec == NULL)
      error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
  
    len = strlen (formspec);
  
    if (strncmp (formspec, "natural", len) == 0)
--- 209,220 ----
    if (var == NULL)
      error (_("mi_cmd_var_set_format: Variable object not found"));
  
!   if (argv[1] == NULL)
      error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
  
+   formspec = xstrdup (argv[1]);
+   make_cleanup (xfree, formspec);
+ 
    len = strlen (formspec);
  
    if (strncmp (formspec, "natural", len) == 0)

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

* Re: [patch] memory leak, mi-cmd-var
  2007-06-29  3:36 [patch] memory leak, mi-cmd-var msnyder
@ 2007-06-29  4:32 ` Nick Roberts
  2007-06-29  4:35   ` msnyder
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Roberts @ 2007-06-29  4:32 UTC (permalink / raw)
  To: msnyder; +Cc: gdb-patches

 > 'nother one from Coverity.
 > 
 > 2007-06-28  Michael Snyder  <msnyder@access-company.com>
 > 
 > 	* mi/mi-cmd-var.c (mi_cmd_var_set_format): Free strduped memory
 > 	(Coverity).  Also take the opportunity to call error earlier
 > 	(before strdup).

I don't see why the string has to be duplicated in the first place or how
argv[1] could be NULL.  Why not just:


*** mi-cmd-var.c	14 Jun 2007 10:12:15 +1200	1.33
--- mi-cmd-var.c	29 Jun 2007 15:35:10 +1200	
*************** mi_cmd_var_set_format (char *command, ch
*** 209,217 ****
    if (var == NULL)
      error (_("mi_cmd_var_set_format: Variable object not found"));
  
!   formspec = xstrdup (argv[1]);
!   if (formspec == NULL)
!     error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
  
    len = strlen (formspec);
  
--- 209,215 ----
    if (var == NULL)
      error (_("mi_cmd_var_set_format: Variable object not found"));
  
!   formspec = argv[1];
  
    len = strlen (formspec);
  


 > Index: mi/mi-cmd-var.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v
 > retrieving revision 1.33
 > diff -p -r1.33 mi-cmd-var.c
 > *** mi/mi-cmd-var.c	13 Jun 2007 19:08:47 -0000	1.33
 > --- mi/mi-cmd-var.c	29 Jun 2007 02:52:39 -0000
 > *************** mi_cmd_var_set_format (char *command, ch
 > *** 209,218 ****
 >     if (var == NULL)
 >       error (_("mi_cmd_var_set_format: Variable object not found"));
 >   
 > !   formspec = xstrdup (argv[1]);
 > !   if (formspec == NULL)
 >       error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
 >   
 >     len = strlen (formspec);
 >   
 >     if (strncmp (formspec, "natural", len) == 0)
 > --- 209,220 ----
 >     if (var == NULL)
 >       error (_("mi_cmd_var_set_format: Variable object not found"));
 >   
 > !   if (argv[1] == NULL)
 >       error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
 >   
 > +   formspec = xstrdup (argv[1]);
 > +   make_cleanup (xfree, formspec);
 > + 
 >     len = strlen (formspec);
 >   
 >     if (strncmp (formspec, "natural", len) == 0)
-- 
Nick                                           http://www.inet.net.nz/~nickrob


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

* Re: [patch] memory leak, mi-cmd-var
  2007-06-29  4:32 ` Nick Roberts
@ 2007-06-29  4:35   ` msnyder
  0 siblings, 0 replies; 3+ messages in thread
From: msnyder @ 2007-06-29  4:35 UTC (permalink / raw)
  To: Nick Roberts; +Cc: msnyder, gdb-patches


 > 'nother one from Coverity.
 >
 > 2007-06-28  Michael Snyder  <msnyder@access-company.com>
 >
 >      * mi/mi-cmd-var.c (mi_cmd_var_set_format): Free strduped memory
 >      (Coverity).  Also take the opportunity to call error earlier
 >      (before strdup).

> I don't see why the string has to be duplicated in the first place or how
> argv[1] could be NULL.  Why not just:

Well... you're right!  At least about the strdup.

About the NULL check -- it was already there, so I don't favor removing
it unles we can demonstrate that it can't be NULL.  But I'll re-submit
after eliminating the strdup.



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

end of thread, other threads:[~2007-06-29  4:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-29  3:36 [patch] memory leak, mi-cmd-var msnyder
2007-06-29  4:32 ` Nick Roberts
2007-06-29  4:35   ` msnyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox