Code auditing weekend results and fixes committing.
[silc.git] / lib / silcutil / silcmemory.c
1 /*
2
3   silcmemory.c
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1999 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20 /* $Id$ */
21
22 #include "silcincludes.h"
23
24 void *silc_malloc(size_t size)
25 {
26   void *addr;
27 #ifdef HAVE_MLOCK
28   addr = malloc(size);
29   assert(addr != NULL);
30   mlock(addr, size);
31   return addr;
32 #else
33   addr = malloc(size);
34   assert(addr != NULL);
35   return addr;
36 #endif
37 }
38
39 void *silc_calloc(size_t items, size_t size)
40 {
41   void *addr;
42 #ifdef HAVE_MLOCK
43   addr = calloc(items, size);
44   assert(addr != NULL);
45   mlock(addr, size);
46   return addr;
47 #else
48   addr = calloc(items, size);
49   assert(addr != NULL);
50   return addr;
51 #endif
52 }
53
54 void *silc_realloc(void *ptr, size_t size)
55 {
56   void *addr;
57 #ifdef HAVE_MLOCK
58   addr = realloc(ptr, size);
59   assert(addr != NULL);
60   mlock(addr, size);
61   return addr;
62 #else
63   addr = realloc(ptr, size);
64   assert(addr != NULL);
65   return addr;
66 #endif
67 }
68
69 void silc_free(void *ptr)
70 {
71   free(ptr);
72 }
73
74
75
76
77
78
79