OpenDNSSEC-enforcer
1.4.5
Main Page
Data Structures
Files
File List
Globals
enforcer
ksm
memory.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008-2009 Nominet UK. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
6
* are met:
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
*
13
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*
25
*/
26
27
/*+
28
* Filename: memory.c
29
*
30
* Description:
31
* Wrappers around memory allocation routines. If any fail,
32
* the program will write a memory exhaustion error to stderr
33
* and terminate.
34
-*/
35
36
#include <stdio.h>
37
#include <stdlib.h>
38
39
#include "
ksm/memory.h
"
40
#include "
ksm/ksmdef.h
"
41
#include "
ksm/message.h
"
42
43
/*+
44
* MemMalloc - Allocate Memory
45
* MemCalloc - Allocate Contiguous Memory
46
* MemRealloc - Reallocate Memory
47
*
48
* Description:
49
* Wrapper routines around the Unix memory allocation routines. If
50
* an allocation routine returns null, an error is logged and the
51
* program exits.
52
*
53
* MemFree is also defined, but as a macro to allow the passed element
54
* to be zeroed. The definition can be found in the header file.
55
-*/
56
57
void
*
MemMalloc
(
size_t
size)
58
{
59
void
*ptr = malloc(size);
60
if
(ptr == NULL) {
61
MsgLog
(
KSM_STMTALLOC
,
"malloc: Out of swap space"
);
62
fprintf(stderr,
"malloc: Out of swap space"
);
63
exit(1);
64
}
65
return
ptr;
66
}
67
68
void
*
MemCalloc
(
size_t
nmemb,
size_t
size)
69
{
70
void
*ptr = calloc(nmemb, size);
71
if
(ptr == NULL) {
72
MsgLog
(
KSM_STMTALLOC
,
"calloc: Out of swap space"
);
73
fprintf(stderr,
"calloc: Out of swap space"
);
74
exit(1);
75
}
76
return
ptr;
77
}
78
79
void
*
MemRealloc
(
void
*ptr,
size_t
size)
80
{
81
void
*ptr1 = realloc(ptr, size);
82
if
(ptr1 == NULL) {
83
MsgLog
(
KSM_STMTALLOC
,
"realloc: Out of swap space"
);
84
fprintf(stderr,
"realloc: Out of swap space"
);
85
exit(1);
86
}
87
return
ptr1;
88
}
Generated on Tue Jul 22 2014 00:37:50 for OpenDNSSEC-enforcer by
1.8.1.2