Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* xmalloc for gdbserver?
@ 2008-11-30 21:59 Doug Evans
  2008-12-01  0:10 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Evans @ 2008-11-30 21:59 UTC (permalink / raw)
  To: gdb

I was going to submit this but then checked for other occurrences
and found a lot.

diff -u -p -r1.15 regcache.c
--- regcache.c	8 Sep 2008 21:16:18 -0000	1.15
+++ regcache.c	30 Nov 2008 21:32:41 -0000
@@ -95,6 +95,8 @@ new_register_cache (void)
     return NULL; /* The architecture hasn't been initialized yet.  */
 
   regcache = malloc (sizeof (*regcache));
+  if (regcache == NULL)
+    fatal ("Could not allocate register cache.");
 
   /* Make sure to zero-initialize the register cache when it is created,
      in case there are registers the target never fetches.  This way they'll


Do we want to create versions of xmalloc, et.al. for gdbserver?
I'll submit a patch for whichever way we choose, I just need to
know which way to go.
[I realize many of these are requests for small amounts, and (a)
segv'ing will be rare, and (b) segv'ing in such a loaded system may be of
lesser value, but still ...]
There are cases where one doesn't want gdbserver to die because
of a malloc failure, I wouldn't willy-nilly start replacing all calls to
use xmalloc per se.

gdbserver$ grep -A3 "malloc *(" *.c
hostio.c:  *data = malloc (p_len);
hostio.c-
hostio.c-  output_index = 0;
hostio.c-  escaped = 0;
--
hostio.c:  new_fd = malloc (sizeof (struct fd_list));
hostio.c-  new_fd->fd = fd;
hostio.c-  new_fd->next = open_fds;
hostio.c-  open_fds = new_fd;
--
hostio.c:  data = malloc (len);
hostio.c-#ifdef HAVE_PREAD
hostio.c-  ret = pread (fd, data, len, offset);
hostio.c-#else
--
inferiors.c:  struct thread_info *new_thread = malloc (sizeof (*new_thread));
inferiors.c-
inferiors.c-  memset (new_thread, 0, sizeof (*new_thread));
inferiors.c-
--
inferiors.c:  struct dll_info *new_dll = malloc (sizeof (*new_dll));
inferiors.c-  memset (new_dll, 0, sizeof (*new_dll));
inferiors.c-
inferiors.c-  new_dll->entry.id = -1;
--
inferiors.c:  new_entry = malloc (sizeof (struct inferior_list_entry));
inferiors.c-  new_entry->id = pid;
inferiors.c-  add_inferior_to_list (list, new_entry);
inferiors.c-}
--
linux-low.c:  process = (struct process_info *) malloc (sizeof (*process));
linux-low.c-  memset (process, 0, sizeof (*process));
linux-low.c-
linux-low.c-  process->head.id = pid;
--
linux-low.c:      p_sig = malloc (sizeof (*p_sig));
linux-low.c-      p_sig->prev = process->pending_signals;
linux-low.c-      p_sig->signal = signal;
linux-low.c-      if (info == NULL)
--
linux-low.c:      p_sig = malloc (sizeof (*p_sig));
linux-low.c-      p_sig->prev = process->pending_signals;
linux-low.c-      p_sig->signal = process->resume->sig;
linux-low.c-      memset (&p_sig->info, 0, sizeof (siginfo_t));
--
linux-low.c:      buf = malloc (regset->size);
linux-low.c-#ifndef __sparc__
linux-low.c-      res = ptrace (regset->get_request, inferior_pid, 0, buf);
linux-low.c-#else
--
linux-low.c:      buf = malloc (regset->size);
linux-low.c-
linux-low.c-      /* First fill the buffer with the current register set contents,
linux-low.c-	 in case there are any items in the kernel's regset that are
--
linux-low.c:  char *stack = malloc (STACK_SIZE * 4);
linux-low.c-
linux-low.c-  linux_supports_tracefork_flag = 0;
linux-low.c-
--
linux-low.c:  disabled_regsets = malloc (num_regsets);
linux-low.c-#endif
linux-low.c-}
--
mem-break.c:  bp = malloc (sizeof (struct breakpoint));
mem-break.c-  memset (bp, 0, sizeof (struct breakpoint));
mem-break.c-
mem-break.c-  (*the_target->read_memory) (where, bp->old_data,
--
regcache.c:  regcache = malloc (sizeof (*regcache));
regcache.c-  if (regcache == NULL)
regcache.c-    fatal ("Could not allocate register cache.");
regcache.c-
--
remote-utils.c:  buf2 = malloc (PBUFSIZ);
remote-utils.c-
remote-utils.c-  /* Copy the packet into buffer BUF2, encapsulating it
remote-utils.c-     and giving it a checksum.  */
--
remote-utils.c:      mem_buf = malloc (mem_len);
remote-utils.c-      if (read_inferior_memory (mem_addr, mem_buf, mem_len) == 0)
remote-utils.c-	convert_int_to_ascii (mem_buf, own_buf, mem_len);
remote-utils.c-      else
--
remote-utils.c:  sym = malloc (sizeof (*sym));
remote-utils.c-  sym->name = strdup (name);
remote-utils.c-  sym->addr = *addrp;
remote-utils.c-  sym->next = symbol_cache;
--
remote-utils.c:  char *buf = malloc (strlen (msg) * 2 + 2);
remote-utils.c-
remote-utils.c-  buf[0] = 'O';
remote-utils.c-  hexify (buf + 1, msg, 0);
--
remote-utils.c:  result = malloc (i + special + 1);
remote-utils.c-  for (i = 0, special = 0; text[i] != '\0'; i++)
remote-utils.c-    switch (text[i])
remote-utils.c-      {
--
server.c:  pattern = malloc (packet_len);
server.c-  if (pattern == NULL)
server.c-    {
server.c-      error ("Unable to allocate memory to perform the search");
--
server.c:  search_buf = malloc (search_buf_size);
server.c-  if (search_buf == NULL)
server.c-    {
server.c-      free (pattern);
--
server.c:      spu_buf = malloc (len + 1);
server.c-      if (!spu_buf)
server.c-        return;
server.c-
--
server.c:      spu_buf = malloc (packet_len - 15);
server.c-      if (!spu_buf)
server.c-        return;
server.c-      if (decode_xfer_write (own_buf + 16, packet_len - 16, &annex,
--
server.c:      data = malloc (len + 1);
server.c-      n = (*the_target->read_auxv) (ofs, data, len + 1);
server.c-      if (n < 0)
server.c-	write_enn (own_buf);
--
server.c:      document = malloc (total_len);
server.c-      strcpy (document, "<library-list>\n");
server.c-      p = document + strlen (document);
server.c-
--
server.c:      char *mon = malloc (PBUFSIZ);
server.c-      int len = strlen (own_buf + 6);
server.c-
server.c-      if ((len % 2) != 0 || unhexify (mon, own_buf + 6, len / 2) != len / 2)
--
server.c:  resume_info = malloc ((n + 1) * sizeof (resume_info[0]));
server.c-
server.c-  default_action.thread = -1;
server.c-  default_action.leave_stopped = 1;
--
server.c:	  new_argv[i] = malloc (1 + (next_p - p) / 2);
server.c-	  unhexify (new_argv[i], p, (next_p - p) / 2);
server.c-	  new_argv[i][(next_p - p) / 2] = '\0';
server.c-	}
--
server.c:  own_buf = malloc (PBUFSIZ + 1);
server.c:  mem_buf = malloc (PBUFSIZ);
server.c-
server.c-  if (pid == 0 && *next_arg != NULL)
server.c-    {
--
server.c:      program_argv = malloc (sizeof (char *) * (n + 1));
server.c-      for (i = 0; i < n; i++)
server.c-	program_argv[i] = strdup (next_arg[i]);
server.c-      program_argv[i] = NULL;
--
target.c:  buffer = malloc (len);
target.c-  memcpy (buffer, myaddr, len);
target.c-  check_mem_write (memaddr, buffer, len);
target.c-  res = (*the_target->write_memory) (memaddr, buffer, len);
--
target.c:  the_target = (struct target_ops *) malloc (sizeof (*the_target));
target.c-  memcpy (the_target, target, sizeof (*the_target));
target.c-}
gdbserver$ 


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

* Re: xmalloc for gdbserver?
  2008-11-30 21:59 xmalloc for gdbserver? Doug Evans
@ 2008-12-01  0:10 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2008-12-01  0:10 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb

On Sun, Nov 30, 2008 at 01:58:40PM -0800, Doug Evans wrote:
> Do we want to create versions of xmalloc, et.al. for gdbserver?
> I'll submit a patch for whichever way we choose, I just need to
> know which way to go.

Seems fine to me.  I just haven't done it because, to the best of my
knowledge, none of them have ever failed :-)

-- 
Daniel Jacobowitz
CodeSourcery


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

end of thread, other threads:[~2008-12-01  0:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-30 21:59 xmalloc for gdbserver? Doug Evans
2008-12-01  0:10 ` Daniel Jacobowitz

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