ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/memory.c
(Generate patch)

Comparing:
ircd-hybrid-7.3/src/memory.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
ircd-hybrid/trunk/src/memory.c (file contents), Revision 5425 by michael, Wed Jan 28 13:37:09 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  memory.c: Memory utilities.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
21 *
22 *  $Id$
20   */
21  
22 + /*! \file memory.c
23 + * \brief Memory utilities.
24 + * \version $Id$
25 + */
26  
27   #include "stdinc.h"
28   #include "ircd_defs.h"
29   #include "irc_string.h"
30   #include "memory.h"
31 < #include "s_log.h"
31 > #include "log.h"
32   #include "restart.h"
33  
34  
35   /*
36 < * MyMalloc - allocate memory, call outofmemory on failure
36 > * MyCalloc - allocate memory, call outofmemory on failure
37   */
38   void *
39 < MyMalloc(size_t size)
39 > MyCalloc(size_t size)
40   {
41    void *ret = calloc(1, size);
42  
# Line 53 | Line 54 | MyRealloc(void *x, size_t y)
54   {
55    void *ret = realloc(x, y);
56  
57 <  if (ret == NULL)
57 >  if (y && ret == NULL)
58      outofmemory();
59  
60    return ret;
# Line 62 | Line 63 | MyRealloc(void *x, size_t y)
63   void
64   MyFree(void *x)
65   {
66 <  if (x)
66 <    free(x);
66 >  free(x);
67   }
68  
69 < void
70 < _DupString(char **x, const char *y)
69 > void *
70 > xstrdup(const char *s)
71   {
72 <  (*x) = malloc(strlen(y) + 1);
73 <  strcpy((*x), y);
72 >  void *ret = malloc(strlen(s) + 1);
73 >
74 >  if (ret == NULL)
75 >    outofmemory();
76 >
77 >  strcpy(ret, s);
78 >
79 >  return ret;
80 > }
81 >
82 > void *
83 > xstrndup(const char *s, size_t len)
84 > {
85 >  void *ret = malloc(len + 1);
86 >
87 >  if (ret == NULL)
88 >    outofmemory();
89 >
90 >  strlcpy(ret, s, len + 1);
91 >
92 >  return ret;
93   }
94  
95   /* outofmemory()
# Line 88 | Line 107 | outofmemory(void)
107    if (was_here++)
108      abort();
109  
110 <  ilog(L_CRIT, "Out of memory: restarting server...");
111 <  restart("Out of Memory");
93 < }
94 <
95 < #ifndef NDEBUG
96 < /*
97 < * frob some memory. debugging time.
98 < * -- adrian
99 < */
100 < void
101 < mem_frob(void *data, int len)
102 < {
103 <  /* correct for Intel only! little endian */
104 <  unsigned char b[4] = { 0xef, 0xbe, 0xad, 0xde };
105 <  int i;
106 <  char *cdata = data;
107 <
108 <  for (i = 0; i < len; i++)
109 <  {
110 <    *cdata = b[i % 4];
111 <    cdata++;
112 <  }
110 >  ilog(LOG_TYPE_IRCD, "Out of memory: restarting server...");
111 >  server_die("Out of Memory", 1);
112   }
114 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)