HASH_OBJ = @HASH_OBJ@
-OBJS = cmdparse.o conf.o local.o logging.o main.o mkdirpp.o reference.o \
- regress.o rtc.o sched.o sources.o sourcestats.o stubs.o sys.o \
- tempcomp.o util.o $(HASH_OBJ)
+OBJS = cmdparse.o conf.o local.o logging.o main.o memory.o mkdirpp.o \
+ reference.o regress.o rtc.o sched.o sources.o sourcestats.o stubs.o \
+ sys.o tempcomp.o util.o $(HASH_OBJ)
EXTRA_OBJS=@EXTRA_OBJECTS@
#include "getdate.h"
#include "cmdparse.h"
#include "pktlength.h"
-#include "memory.h"
#include "util.h"
#ifdef FEAT_READLINE
switch (status) {
case CPS_Success:
if (DNS_Name2IPAddress(data.name, &ip_addr) != DNS_Success) {
- Free(data.name);
+ free(data.name);
fprintf(stderr, "Invalid host/IP address\n");
break;
}
- Free(data.name);
+ free(data.name);
if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM) {
fprintf(stderr, "Option minstratum not supported\n");
parse_string(char *line, char **result)
{
check_number_of_args(line, 1);
- *result = strdup(line);
+ *result = Strdup(line);
return 1;
}
return;
}
- name = strdup(p);
+ name = Strdup(p);
p = line;
line = CPS_SplitWord(line);
- param = strdup(p);
+ param = Strdup(p);
while (*line) {
cmd = line;
address = line;
line = CPS_SplitWord(line);
if (sscanf(line, "%lf", &mail_change_threshold) == 1) {
- mail_user_on_change = strdup(address);
+ mail_user_on_change = Strdup(address);
} else {
mail_user_on_change = NULL;
command_parse_error();
return;
}
- tempcomp_file = strdup(p);
+ tempcomp_file = Strdup(p);
}
/* ================================================== */
ptr->next->prev = ptr->prev;
ptr->prev->next = ptr->next;
- free(ptr);
+ Free(ptr);
}
/* ================================================== */
ptr->next->prev = ptr->prev;
ptr->prev->next = ptr->next;
- free(ptr);
+ Free(ptr);
}
/* ================================================== */
LOGF_Local,
LOGF_Util,
LOGF_Main,
+ LOGF_Memory,
LOGF_ClientLog,
LOGF_Configure,
LOGF_CmdMon,
--- /dev/null
+/*
+ chronyd/chronyc - Programs for keeping computer clocks accurate.
+
+ **********************************************************************
+ * Copyright (C) Miroslav Lichvar 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ **********************************************************************
+
+ =======================================================================
+
+ Utility functions for memory allocation.
+
+ */
+
+#include "config.h"
+
+#include "logging.h"
+#include "memory.h"
+
+void *
+Malloc(size_t size)
+{
+ void *r;
+
+ r = malloc(size);
+ if (!r && size)
+ LOG_FATAL(LOGF_Memory, "Could not allocate memory");
+
+ return r;
+}
+
+void *
+Realloc(void *ptr, size_t size)
+{
+ void *r;
+
+ r = realloc(ptr, size);
+ if (!r && size)
+ LOG_FATAL(LOGF_Memory, "Could not allocate memory");
+
+ return r;
+}
+
+char *
+Strdup(const char *s)
+{
+ void *r;
+
+ r = strdup(s);
+ if (!r)
+ LOG_FATAL(LOGF_Memory, "Could not allocate memory");
+
+ return r;
+}
#ifndef GOT_MEMORY_H
#define GOT_MEMORY_H
-#define Malloc(x) malloc(x)
-#define MallocNew(T) ((T *) malloc(sizeof(T)))
-#define MallocArray(T, n) ((T *) malloc((n) * sizeof(T)))
-#define Realloc(x,y) realloc(x,y)
-#define ReallocArray(T,n,x) ((T *) realloc((void *)(x), (n)*sizeof(T)))
+/* Wrappers checking for errors */
+extern void *Malloc(size_t size);
+extern void *Realloc(void *ptr, size_t size);
+extern char *Strdup(const char *s);
+
+/* Convenient macros */
+#define MallocNew(T) ((T *) Malloc(sizeof(T)))
+#define MallocArray(T, n) ((T *) Malloc((n) * sizeof(T)))
+#define ReallocArray(T,n,x) ((T *) Realloc((void *)(x), (n)*sizeof(T)))
#define Free(x) free(x)
#endif /* GOT_MEMORY_H */
#include "sysincl.h"
+#include "memory.h"
#include "mkdirpp.h"
static int
int i, j, k, last;
len = strlen(path);
- p = (char *) malloc(1 + len);
+ p = (char *)Malloc(1 + len);
i = k = 0;
while (1) {
p[i] = 0;
if (do_dir(p) < 0) {
- free(p);
+ Free(p);
return 0;
}
}
- free(p);
+ Free(p);
return 1;
}