aboutsummaryrefslogtreecommitdiff
path: root/src/util/common_allocation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-30 13:41:07 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-30 13:41:07 +0000
commite67c5886c645a5fda7753d3f72f62ea655d6655b (patch)
tree3058a0f96ddc820a97e38e47d87e6ebf685b23b8 /src/util/common_allocation.c
parentd59ea5663203392637e84dea69feb9671ca2a3de (diff)
downloadgnunet-e67c5886c645a5fda7753d3f72f62ea655d6655b.tar.gz
gnunet-e67c5886c645a5fda7753d3f72f62ea655d6655b.zip
fixes
Diffstat (limited to 'src/util/common_allocation.c')
-rw-r--r--src/util/common_allocation.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 5be7caaa7..e62c12d08 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -47,19 +47,36 @@ static LONG mem_used = 0;
47 * this function (or GNUNET_malloc) to allocate more than several MB 47 * this function (or GNUNET_malloc) to allocate more than several MB
48 * of memory, if you are possibly needing a very large chunk use 48 * of memory, if you are possibly needing a very large chunk use
49 * GNUNET_xmalloc_unchecked_ instead. 49 * GNUNET_xmalloc_unchecked_ instead.
50 * @param filename where in the code was the call to GNUNET_array_grow 50 * @param filename where in the code was the call to GNUNET_malloc
51 * @param linenumber where in the code was the call to GNUNET_array_grow 51 * @param linenumber where in the code was the call to GNUNET_malloc
52 * @return pointer to size bytes of memory 52 * @return pointer to size bytes of memory
53 */ 53 */
54void * 54void *
55GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) 55GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
56{ 56{
57 void *ret;
57 /* As a security precaution, we generally do not allow very large 58 /* As a security precaution, we generally do not allow very large
58 allocations using the default 'GNUNET_malloc' macro */ 59 allocations using the default 'GNUNET_malloc' macro */
59 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); 60 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
60 return GNUNET_xmalloc_unchecked_ (size, filename, linenumber); 61 ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
62 if (ret == NULL)
63 {
64 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
65 abort ();
66 }
67 return ret;
61} 68}
62 69
70
71/**
72 * Wrapper around malloc. Allocates size bytes of memory.
73 * The memory will be zero'ed out.
74 *
75 * @param size the number of bytes to allocate
76 * @param filename where in the code was the call to GNUNET_malloc_large
77 * @param linenumber where in the code was the call to GNUNET_malloc_large
78 * @return pointer to size bytes of memory, NULL if we do not have enough memory
79 */
63void * 80void *
64GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) 81GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
65{ 82{
@@ -74,10 +91,7 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
74 GNUNET_assert_at (size < INT_MAX, filename, linenumber); 91 GNUNET_assert_at (size < INT_MAX, filename, linenumber);
75 result = malloc (size); 92 result = malloc (size);
76 if (result == NULL) 93 if (result == NULL)
77 { 94 return NULL;
78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
79 abort ();
80 }
81 memset (result, 0, size); 95 memset (result, 0, size);
82 96
83#ifdef W32_MEM_LIMIT 97#ifdef W32_MEM_LIMIT
@@ -148,8 +162,8 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
148 * Dup a string (same semantics as strdup). 162 * Dup a string (same semantics as strdup).
149 * 163 *
150 * @param str the string to dup 164 * @param str the string to dup
151 * @param filename where in the code was the call to GNUNET_array_grow 165 * @param filename where in the code was the call to GNUNET_strdup
152 * @param linenumber where in the code was the call to GNUNET_array_grow 166 * @param linenumber where in the code was the call to GNUNET_strdup
153 * @return strdup(str) 167 * @return strdup(str)
154 */ 168 */
155char * 169char *