浏览代码

perf tools: Introduce xzalloc() for detecting out of memory conditions

Introducing xzalloc() which wrapping zalloc() for detecting out
of memory conditions.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20100316220521.32050.85155.stgit@localhost6.localdomain6>
[ -v2: small cleanups in surrounding code ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Masami Hiramatsu 15 年之前
父节点
当前提交
a1d37d5285
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      tools/perf/util/util.h

+ 9 - 0
tools/perf/util/util.h

@@ -295,6 +295,13 @@ extern void *xmemdupz(const void *data, size_t len);
 extern char *xstrndup(const char *str, size_t len);
 extern char *xstrndup(const char *str, size_t len);
 extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
 extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
 
 
+static inline void *xzalloc(size_t size)
+{
+	void *buf = xmalloc(size);
+
+	return memset(buf, 0, size);
+}
+
 static inline void *zalloc(size_t size)
 static inline void *zalloc(size_t size)
 {
 {
 	return calloc(1, size);
 	return calloc(1, size);
@@ -309,6 +316,7 @@ static inline int has_extension(const char *filename, const char *ext)
 {
 {
 	size_t len = strlen(filename);
 	size_t len = strlen(filename);
 	size_t extlen = strlen(ext);
 	size_t extlen = strlen(ext);
+
 	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
 	return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
 }
 }
 
 
@@ -322,6 +330,7 @@ static inline int has_extension(const char *filename, const char *ext)
 #undef isalnum
 #undef isalnum
 #undef tolower
 #undef tolower
 #undef toupper
 #undef toupper
+
 extern unsigned char sane_ctype[256];
 extern unsigned char sane_ctype[256];
 #define GIT_SPACE		0x01
 #define GIT_SPACE		0x01
 #define GIT_DIGIT		0x02
 #define GIT_DIGIT		0x02