This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RFA: Fix memory leak in sim_parse_args


Hi!

There are several memory leaks in 'sim_parse_args'. The patch below
fixes them.

Can you approve it?

	Stephane

2000-11-24  Stephane Carrez  <Stephane.Carrez@worldnet.fr>

	* sim-options.c (sim_parse_args): Free the memory used for
	long_options, short_options, handlers, opt_cpu, orig_val.
RCS file: /cvs/src/src/sim/common/sim-options.c,v
retrieving revision 1.1.1.3
diff -p -r1.1.1.3 sim-options.c
*** sim-options.c	1999/12/14 01:06:04	1.1.1.3
--- sim-options.c	2000/11/24 20:26:24
*************** sim_parse_args (sd, argv)
*** 499,504 ****
--- 499,505 ----
    const OPTION *opt;
    OPTION_HANDLER **handlers;
    sim_cpu **opt_cpu;
+   SIM_RC result = SIM_RC_OK;
  
    /* Count the number of arguments.  */
    for (argc = 0; argv[argc] != NULL; ++argc)
*************** sim_parse_args (sd, argv)
*** 579,585 ****
  	    if (opt->shortopt != 0)
  	      {
  		sim_io_eprintf (sd, "internal error, short cpu specific option");
! 		return SIM_RC_FAIL;
  	      }
  	    if (opt->opt.name != NULL)
  	      {
--- 580,587 ----
  	    if (opt->shortopt != 0)
  	      {
  		sim_io_eprintf (sd, "internal error, short cpu specific option");
! 		result = SIM_RC_FAIL;
! 		break;
  	      }
  	    if (opt->opt.name != NULL)
  	      {
*************** sim_parse_args (sd, argv)
*** 617,629 ****
  	  break;
  	}
        if (optc == '?')
! 	return SIM_RC_FAIL;
  
        if ((*handlers[optc]) (sd, opt_cpu[optc], orig_val[optc], optarg, 0/*!is_command*/) == SIM_RC_FAIL)
! 	return SIM_RC_FAIL;
      }
  
!   return SIM_RC_OK;
  }
  
  /* Utility of sim_print_help to print a list of option tables.  */
--- 619,642 ----
  	  break;
  	}
        if (optc == '?')
! 	{
! 	  result = SIM_RC_FAIL;
! 	  break;
! 	}
  
        if ((*handlers[optc]) (sd, opt_cpu[optc], orig_val[optc], optarg, 0/*!is_command*/) == SIM_RC_FAIL)
! 	{
! 	  result = SIM_RC_FAIL;
! 	  break;
! 	}
      }
  
!   zfree (long_options);
!   zfree (short_options);
!   zfree (handlers);
!   zfree (opt_cpu);
!   zfree (orig_val);
!   return result;
  }
  
  /* Utility of sim_print_help to print a list of option tables.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]