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]

[PATCH]: Fix device memory allocation in 68hc11 simulator


Hi!

In the simulator hardware emulation, it's better to use hw_malloc() and
hw_free() so that it's freed automatically by hw_delete() when the
device is deleted.

I've commited this patch to solve this pb.

	Stephane

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

	* dv-m68hc11eepr.c (attach_m68hc11eepr_regs): Use hw_malloc.
	* dv-nvram.c (attach_nvram_regs): Use hw_free and hw_malloc
	instead of free and malloc.
Index: dv-m68hc11eepr.c
===================================================================
RCS file: /cvs/src/src/sim/m68hc11/dv-m68hc11eepr.c,v
retrieving revision 1.2
diff -p -r1.2 dv-m68hc11eepr.c
*** dv-m68hc11eepr.c	2000/08/11 18:44:59	1.2
--- dv-m68hc11eepr.c	2000/11/24 20:49:31
*************** attach_m68hc11eepr_regs (struct hw *me,
*** 218,224 ****
    
    controller->attach_space = attach_space;
    controller->base_address = attach_address;
!   controller->eeprom = (char*) malloc (attach_size + 1);
    controller->eeprom_min_cycles = 10000;
    controller->size = attach_size + 1;
    controller->mapped = 0;
--- 218,224 ----
    
    controller->attach_space = attach_space;
    controller->base_address = attach_address;
!   controller->eeprom = (char*) hw_malloc (me, attach_size + 1);
    controller->eeprom_min_cycles = 10000;
    controller->size = attach_size + 1;
    controller->mapped = 0;
Index: dv-nvram.c
===================================================================
RCS file: /cvs/src/src/sim/m68hc11/dv-nvram.c,v
retrieving revision 1.2
diff -p -r1.2 dv-nvram.c
*** dv-nvram.c	2000/08/11 18:44:59	1.2
--- dv-nvram.c	2000/11/24 20:49:35
*************** attach_nvram_regs (struct hw *me, struct
*** 187,193 ****
  
      case NVRAM_SAVE_MODIFIED:
      case NVRAM_SAVE_ALL:
!       controller->data = (char*) malloc (attach_size);
        if (controller->data == 0)
          hw_abort (me, "Not enough memory, try to use the mode 'map'");
  
--- 187,193 ----
  
      case NVRAM_SAVE_MODIFIED:
      case NVRAM_SAVE_ALL:
!       controller->data = (char*) hw_malloc (me, attach_size);
        if (controller->data == 0)
          hw_abort (me, "Not enough memory, try to use the mode 'map'");
  
*************** attach_nvram_regs (struct hw *me, struct
*** 204,210 ****
            if (result != attach_size)
              {
                oerrno = errno;
!               free (controller->data);
                close (controller->fd);
                errno = oerrno;
                hw_abort (me, "Failed to save the ram content");
--- 204,210 ----
            if (result != attach_size)
              {
                oerrno = errno;
!               hw_free (me, controller->data);
                close (controller->fd);
                errno = oerrno;
                hw_abort (me, "Failed to save the ram content");
*************** attach_nvram_regs (struct hw *me, struct
*** 216,222 ****
            if (result != attach_size)
              {
                oerrno = errno;
!               free (controller->data);
                close (controller->fd);
                errno = oerrno;
                hw_abort (me, "Failed to load the ram content");
--- 216,222 ----
            if (result != attach_size)
              {
                oerrno = errno;
!               hw_free (me, controller->data);
                close (controller->fd);
                errno = oerrno;
                hw_abort (me, "Failed to load the ram content");

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