]>
git.ipfire.org Git - thirdparty/chrony.git/blob - memory.c
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2014, 2017
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **********************************************************************
22 =======================================================================
24 Utility functions for memory allocation.
40 LOG_FATAL("Could not allocate memory");
46 Realloc(void *ptr
, size_t size
)
50 r
= realloc(ptr
, size
);
52 LOG_FATAL("Could not allocate memory");
58 get_array_size(size_t nmemb
, size_t size
)
62 array_size
= nmemb
* size
;
64 /* Check for overflow */
65 if (nmemb
> 0 && array_size
/ nmemb
!= size
)
66 LOG_FATAL("Could not allocate memory");
72 Malloc2(size_t nmemb
, size_t size
)
74 return Malloc(get_array_size(nmemb
, size
));
78 Realloc2(void *ptr
, size_t nmemb
, size_t size
)
80 return Realloc(ptr
, get_array_size(nmemb
, size
));
90 LOG_FATAL("Could not allocate memory");