From: Ben Pfaff Date: Fri, 9 Jan 2009 00:32:21 +0000 (-0800) Subject: Mark memory allocation functions with __attribute__((malloc)). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cca24ca5f13c2232fdf96138ca8a16f43776940b;p=openvswitch Mark memory allocation functions with __attribute__((malloc)). This may improve optimization, and it may make it easier for tools such as Fortify to see what is going on. --- diff --git a/lib/compiler.h b/lib/compiler.h index 2e185bfa..c42c6e4e 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford +/* Copyright (c) 2008, 2009 The Board of Trustees of The Leland Stanford * Junior University * * We are making the OpenFlow specification and associated documentation @@ -39,6 +39,7 @@ #define PACKED __attribute__((__packed__)) #define PRINTF_FORMAT(FMT, ARG1) __attribute__((__format__(printf, FMT, ARG1))) #define STRFTIME_FORMAT(FMT) __attribute__((__format__(__strftime__, FMT, 0))) +#define MALLOC_LIKE __attribute__((__malloc__)) #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) diff --git a/lib/util.h b/lib/util.h index 9c38450c..fde681fa 100644 --- a/lib/util.h +++ b/lib/util.h @@ -95,14 +95,14 @@ extern "C" { void set_program_name(const char *); void out_of_memory(void) NO_RETURN; -void *xmalloc(size_t); -void *xcalloc(size_t, size_t); +void *xmalloc(size_t) MALLOC_LIKE; +void *xcalloc(size_t, size_t) MALLOC_LIKE; void *xrealloc(void *, size_t); -void *xmemdup(const void *, size_t); -char *xmemdup0(const char *, size_t); -char *xstrdup(const char *); -char *xasprintf(const char *format, ...) PRINTF_FORMAT(1, 2); -char *xvasprintf(const char *format, va_list) PRINTF_FORMAT(1, 0); +void *xmemdup(const void *, size_t) MALLOC_LIKE; +char *xmemdup0(const char *, size_t) MALLOC_LIKE; +char *xstrdup(const char *) MALLOC_LIKE; +char *xasprintf(const char *format, ...) PRINTF_FORMAT(1, 2) MALLOC_LIKE; +char *xvasprintf(const char *format, va_list) PRINTF_FORMAT(1, 0) MALLOC_LIKE; void *x2nrealloc(void *p, size_t *n, size_t s); #ifndef HAVE_STRLCPY