Skip to content

Commit db47303

Browse files
committed
Add safe_realloc
1 parent 72f3d3d commit db47303

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/safe.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* vim: set et ts=4 sts=4 sw=4 : */
12
/********************************************************************\
23
* This program is free software; you can redistribute it and/or *
34
* modify it under the terms of the GNU General Public License as *
@@ -55,6 +56,18 @@ void * safe_malloc (size_t size) {
5556
return (retval);
5657
}
5758

59+
void *
60+
safe_realloc(void *ptr, size_t newsize)
61+
{
62+
void *retval = NULL;
63+
retval = realloc(ptr, newsize);
64+
if (NULL == retval) {
65+
debug(LOG_CRIT, "Failed to realloc buffer to %d bytes of memory: %s. Bailing out", newsize, strerror(errno));
66+
exit(1);
67+
}
68+
return retval;
69+
}
70+
5871
char * safe_strdup(const char *s) {
5972
char * retval = NULL;
6073
if (!s) {

src/safe.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@
3333

3434
/** @brief Safe version of malloc
3535
*/
36-
void * safe_malloc (size_t size);
36+
void *safe_malloc(size_t);
37+
38+
/** @brief Safe version of realloc */
39+
void *realloc(void *, size_t);
3740

3841
/* @brief Safe version of strdup
3942
*/
40-
char * safe_strdup(const char *s);
43+
char * safe_strdup(const char *);
4144

4245
/* @brief Safe version of asprintf
4346
*/
44-
int safe_asprintf(char **strp, const char *fmt, ...);
47+
int safe_asprintf(char **, const char *, ...);
4548

4649
/* @brief Safe version of vasprintf
4750
*/
48-
int safe_vasprintf(char **strp, const char *fmt, va_list ap);
51+
int safe_vasprintf(char **, const char *, va_list);
4952

5053
/* @brief Safe version of fork
5154
*/

0 commit comments

Comments
 (0)