This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] Change malloc to xmalloc
- To: <gdb-patches at sourceware dot cygnus dot com>
- Subject: [RFA] Change malloc to xmalloc
- From: "Rudy Folden" <rfolden at redhat dot com>
- Date: Tue, 23 Jan 2001 16:13:37 -0600
Changed calls within gdb from malloc to xmalloc. Of course, the file
utils.c can not be changed since it implements xmalloc via a call to mmalloc
which in turn calls the real malloc.
This has been tested on a Red Hat Linux 7.0 system.
2001-01-22 Rudy Folden <rfolden@redhat.com>
* defs.h: Changed all occurances of malloc to xmalloc
* gdbtypes.c: Likewise.
* gnu-nat.c: Likewise.
* hp-psymtab-read.c: Likewise.
* infttrace.c: Likewise.
* procfs.c: Likewise.
* remote-rdp.c: Likewise.
* stop-gdb.c: Likewise.
* stuff.c: Likewise.
* valprint.c: Likewise.
* config/pa/xm-hppah.h: Likewise.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.34
diff -c -3 -p -r1.34 defs.h
*** defs.h 2001/01/19 08:01:46 1.34
--- defs.h 2001/01/23 21:01:16
*************** extern double atof (const char *); /* X3
*** 962,968 ****
#ifndef MALLOC_INCOMPATIBLE
#ifdef NEED_DECLARATION_MALLOC
! extern PTR malloc ();
#endif
#ifdef NEED_DECLARATION_REALLOC
--- 962,968 ----
#ifndef MALLOC_INCOMPATIBLE
#ifdef NEED_DECLARATION_MALLOC
! extern PTR xmalloc ();
#endif
#ifdef NEED_DECLARATION_REALLOC
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.16
diff -c -3 -p -r1.16 gdbtypes.c
*** gdbtypes.c 2000/12/15 01:01:47 1.16
--- gdbtypes.c 2001/01/23 21:01:19
*************** cfront_mangle_name (struct type *type, i
*** 1350,1356 ****
}
ADD_EXTRA ('\0')
printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
! arm_mangled_name = malloc (strlen (mangled_name) + extras.len);
sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
xfree (mangled_name);
mangled_name = arm_mangled_name;
--- 1350,1356 ----
}
ADD_EXTRA ('\0')
printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
! arm_mangled_name = xmalloc (strlen (mangled_name) + extras.len);
sprintf (arm_mangled_name, "%s%s", mangled_name, extras.str);
xfree (mangled_name);
mangled_name = arm_mangled_name;
Index: gnu-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/gnu-nat.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 gnu-nat.c
*** gnu-nat.c 2000/12/15 01:01:47 1.9
--- gnu-nat.c 2001/01/23 21:01:23
*************** make_proc (struct inf *inf, mach_port_t
*** 538,544 ****
{
error_t err;
mach_port_t prev_port = MACH_PORT_NULL;
! struct proc *proc = malloc (sizeof (struct proc));
proc->port = port;
proc->tid = tid;
--- 538,544 ----
{
error_t err;
mach_port_t prev_port = MACH_PORT_NULL;
! struct proc *proc = xmalloc (sizeof (struct proc));
proc->port = port;
proc->tid = tid;
*************** _proc_free (struct proc *proc)
*** 635,641 ****
struct inf *
make_inf (void)
{
! struct inf *inf = malloc (sizeof (struct inf));
if (!inf)
return 0;
--- 635,641 ----
struct inf *
make_inf (void)
{
! struct inf *inf = xmalloc (sizeof (struct inf));
if (!inf)
return 0;
Index: hp-psymtab-read.c
===================================================================
RCS file: /cvs/src/src/gdb/hp-psymtab-read.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 hp-psymtab-read.c
*** hp-psymtab-read.c 2000/12/15 01:01:47 1.8
--- hp-psymtab-read.c 2001/01/23 21:01:25
*************** hpread_call_pxdb (char *file_name)
*** 118,124 ****
if (file_exists (PXDB_SVR4))
{
! p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
strcpy (p, PXDB_SVR4);
strcat (p, " ");
strcat (p, file_name);
--- 118,124 ----
if (file_exists (PXDB_SVR4))
{
! p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
strcpy (p, PXDB_SVR4);
strcat (p, " ");
strcat (p, file_name);
*************** hpread_quick_traverse (struct objfile *o
*** 946,952 ****
static_syms);
/* Set up to only enter each class referenced in this module once.
*/
! class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
--- 946,952 ----
static_syms);
/* Set up to only enter each class referenced in this module once.
*/
! class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
*************** hpread_quick_traverse (struct objfile *o
*** 1174,1180 ****
static_syms);
/* Set up to only enter each class referenced in this module once.
*/
! class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
--- 1174,1180 ----
static_syms);
/* Set up to only enter each class referenced in this module once.
*/
! class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries));
B_CLRALL (class_entered, pxdb_header_p->cd_entries);
/* Scan the procedure descriptors for procedures in the current
Index: infttrace.c
===================================================================
RCS file: /cvs/src/src/gdb/infttrace.c,v
retrieving revision 1.7
diff -c -3 -p -r1.7 infttrace.c
*** infttrace.c 2000/12/15 01:01:47 1.7
--- infttrace.c 2001/01/23 21:01:33
*************** create_thread_info (int pid, lwpid_t tid
*** 601,607 ****
thread_info *p;
int thread_count_of_pid;
! new_p = malloc (sizeof (thread_info));
new_p->pid = pid;
new_p->tid = tid;
new_p->have_signal = 0;
--- 601,607 ----
thread_info *p;
int thread_count_of_pid;
! new_p = xmalloc (sizeof (thread_info));
new_p->pid = pid;
new_p->tid = tid;
new_p->have_signal = 0;
*************** kill_inferior (void)
*** 3829,3835 ****
zaps the target vector.
*/
! paranoia = (thread_info **) malloc (thread_head.count *
sizeof (thread_info *));
para_count = 0;
--- 3829,3835 ----
zaps the target vector.
*/
! paranoia = (thread_info **) xmalloc (thread_head.count *
sizeof (thread_info *));
para_count = 0;
Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.22
diff -c -3 -p -r1.22 procfs.c
*** procfs.c 2001/01/16 17:41:51 1.22
--- procfs.c 2001/01/23 21:01:37
*************** proc_update_threads (procinfo *pi)
*** 2876,2883 ****
return 1; /* Process is not multi-threaded; nothing to do. */
if ((prstatus = (gdb_prstatus_t *)
! malloc (sizeof (gdb_prstatus_t) * (nlwp + 1))) == 0)
! perror_with_name ("procfs: malloc failed in update_threads");
old_chain = make_cleanup (xfree, prstatus);
if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
--- 2876,2883 ----
return 1; /* Process is not multi-threaded; nothing to do. */
if ((prstatus = (gdb_prstatus_t *)
! xmalloc (sizeof (gdb_prstatus_t) * (nlwp + 1))) == 0)
! perror_with_name ("procfs: xmalloc failed in update_threads");
old_chain = make_cleanup (xfree, prstatus);
if (ioctl (pi->ctl_fd, PIOCLSTATUS, prstatus) < 0)
*************** proc_update_threads (procinfo *pi)
*** 2983,2990 ****
if (nthreads < 2)
return 0; /* nothing to do for 1 or fewer threads */
! if ((threads = malloc (nthreads * sizeof (tid_t))) == NULL)
! proc_error (pi, "update_threads, malloc", __LINE__);
if (ioctl (pi->ctl_fd, PIOCTLIST, threads) < 0)
proc_error (pi, "procfs: update_threads (PIOCTLIST)", __LINE__);
--- 2983,2990 ----
if (nthreads < 2)
return 0; /* nothing to do for 1 or fewer threads */
! if ((threads = xmalloc (nthreads * sizeof (tid_t))) == NULL)
! proc_error (pi, "update_threads, xmalloc", __LINE__);
if (ioctl (pi->ctl_fd, PIOCTLIST, threads) < 0)
proc_error (pi, "procfs: update_threads (PIOCTLIST)", __LINE__);
Index: remote-rdp.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-rdp.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 remote-rdp.c
*** remote-rdp.c 2000/12/15 01:01:49 1.8
--- remote-rdp.c 2001/01/23 21:01:38
*************** rdp_set_command_line (char *command, cha
*** 698,704 ****
if (commandline != NULL)
xfree (commandline);
! commandline = malloc (strlen (command) + strlen (args) + 2);
if (commandline != NULL)
{
strcpy (commandline, command);
--- 698,704 ----
if (commandline != NULL)
xfree (commandline);
! commandline = xmalloc (strlen (command) + strlen (args) + 2);
if (commandline != NULL)
{
strcpy (commandline, command);
Index: stop-gdb.c
===================================================================
RCS file: /cvs/src/src/gdb/stop-gdb.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 stop-gdb.c
*** stop-gdb.c 2000/07/30 01:48:27 1.2
--- stop-gdb.c 2001/01/23 21:01:38
*************** main (int argc, char **argv)
*** 65,71 ****
else
host = (char *) "";
! name = malloc (strlen (argv[1]) + sizeof (GDB_NAME_PREFIX));
if (name == NULL)
{
fprintf (stderr, "Unable to allocate memory for name.");
--- 65,71 ----
else
host = (char *) "";
! name = xmalloc (strlen (argv[1]) + sizeof (GDB_NAME_PREFIX));
if (name == NULL)
{
fprintf (stderr, "Unable to allocate memory for name.");
Index: stuff.c
===================================================================
RCS file: /cvs/src/src/gdb/stuff.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 stuff.c
*** stuff.c 2000/07/30 01:48:27 1.2
--- stuff.c 2001/01/23 21:01:38
*************** get_offset (char *file, char *sym_name)
*** 111,117 ****
err ("File %s not an a.out file\n", file);
/* read in symbol table */
! if ((symbol_table = (struct nlist *) malloc (file_hdr.a_syms)) == 0)
err ("Couldn't allocate space for symbol table\n");
if (lseek (f, N_SYMOFF (file_hdr), 0) == -1)
err ("lseek error: %s\n", strerror (errno));
--- 111,117 ----
err ("File %s not an a.out file\n", file);
/* read in symbol table */
! if ((symbol_table = (struct nlist *) xmalloc (file_hdr.a_syms)) == 0)
err ("Couldn't allocate space for symbol table\n");
if (lseek (f, N_SYMOFF (file_hdr), 0) == -1)
err ("lseek error: %s\n", strerror (errno));
*************** get_offset (char *file, char *sym_name)
*** 122,128 ****
/* read in string table */
if (read (f, &size, 4) == -1)
err ("reading string table size: %s\n", strerror (errno));
! if ((strings = (char *) malloc (size)) == 0)
err ("Couldn't allocate memory for string table\n");
if (read (f, strings, size - 4) == -1)
err ("reading string table: %s\n", strerror (errno));
--- 122,128 ----
/* read in string table */
if (read (f, &size, 4) == -1)
err ("reading string table size: %s\n", strerror (errno));
! if ((strings = (char *) xmalloc (size)) == 0)
err ("Couldn't allocate memory for string table\n");
if (read (f, strings, size - 4) == -1)
err ("reading string table: %s\n", strerror (errno));
Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.9
diff -c -3 -p -r1.9 valprint.c
*** valprint.c 2000/12/15 01:01:50 1.9
--- valprint.c 2001/01/23 21:01:45
*************** print_decimal_chars (struct ui_file *str
*** 886,892 ****
* as the base 16 number, which is 2 digits per byte.
*/
decimal_len = len * 2 * 2;
! digits = (unsigned char *) malloc (decimal_len);
if (digits == NULL)
error ("Can't allocate memory for conversion to decimal.");
--- 886,892 ----
* as the base 16 number, which is 2 digits per byte.
*/
decimal_len = len * 2 * 2;
! digits = (unsigned char *) xmalloc (decimal_len);
if (digits == NULL)
error ("Can't allocate memory for conversion to decimal.");
Index: config/pa/xm-hppah.h
===================================================================
RCS file: /cvs/src/src/gdb/config/pa/xm-hppah.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 xm-hppah.h
*** xm-hppah.h 2000/05/28 01:12:37 1.2
--- xm-hppah.h 2001/01/23 21:01:47
***************
*** 40,46 ****
#define MALLOC_INCOMPATIBLE
! extern void *malloc (size_t);
extern void *realloc (void *, size_t);
--- 40,46 ----
#define MALLOC_INCOMPATIBLE
! extern void *xmalloc (size_t);
extern void *realloc (void *, size_t);