summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2010-05-26 22:27:01 +0300
committerMichael Widenius <monty@askmonty.org>2010-05-26 22:27:01 +0300
commit9e23495b1dc988526776768f50a30f647d793d14 (patch)
tree8f5166007a2603ef6cb45ddd08beca6b6da3a3fd
parent2d43ff67ddab70e6fb89682e201cb788c845e71e (diff)
downloadmariadb-git-9e23495b1dc988526776768f50a30f647d793d14.tar.gz
Added macros to inform valgrind that memory is uninitialized
include/Makefile.am: Make my_valgrind.h global (as it's used by my_global.h) include/my_global.h: Include my_valgrind.h include/my_sys.h: TRASH() moved to my_valgrind.h include/my_valgrind.h: Add VALGRIND defines to mark memory mysys/my_alloc.c: Mark internal freed memory as undefined
-rw-r--r--include/Makefile.am2
-rw-r--r--include/my_global.h8
-rw-r--r--include/my_sys.h2
-rw-r--r--include/my_valgrind.h38
-rw-r--r--mysys/my_alloc.c3
5 files changed, 42 insertions, 11 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 516fdeee392..4d932d3159c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -23,7 +23,7 @@ HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \
pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
my_xml.h mysql_embed.h \
my_pthread.h my_no_pthread.h \
- decimal.h errmsg.h my_global.h my_net.h \
+ decimal.h errmsg.h my_global.h my_valgrind.h my_net.h \
my_getopt.h sslopt-longopts.h my_dir.h \
sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \
diff --git a/include/my_global.h b/include/my_global.h
index 2c64f25626b..a32db3c87b6 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -566,18 +566,14 @@ int __void__;
#define LINT_INIT(var)
#endif
+#include <my_valgrind.h>
+
#if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_valgrind)
#define VALGRIND_OR_LINT_INIT(var) var=0
#else
#define VALGRIND_OR_LINT_INIT(var)
#endif
-#ifdef HAVE_valgrind
-#define IF_VALGRIND(A,B) (A)
-#else
-#define IF_VALGRIND(A,B) (B)
-#endif
-
/*
Suppress uninitialized variable warning without generating code.
diff --git a/include/my_sys.h b/include/my_sys.h
index 519204455e1..aa0e8d7f20d 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -145,7 +145,6 @@ extern int NEAR my_errno; /* Last error in mysys */
#define my_memdup(A,B,C) _my_memdup((A),(B), __FILE__,__LINE__,C)
#define my_strdup(A,C) _my_strdup((A), __FILE__,__LINE__,C)
#define my_strndup(A,B,C) _my_strndup((A),(B),__FILE__,__LINE__,C)
-
#define QUICK_SAFEMALLOC sf_malloc_quick=1
#define NORMAL_SAFEMALLOC sf_malloc_quick=0
extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
@@ -173,7 +172,6 @@ extern char *my_strndup(const char *from, size_t length,
#define CALLER_INFO_PROTO /* nothing */
#define CALLER_INFO /* nothing */
#define ORIG_CALLER_INFO /* nothing */
-#define TRASH(A,B) /* nothing */
#endif
#if defined(ENABLED_DEBUG_SYNC)
diff --git a/include/my_valgrind.h b/include/my_valgrind.h
new file mode 100644
index 00000000000..301f9f85464
--- /dev/null
+++ b/include/my_valgrind.h
@@ -0,0 +1,38 @@
+/* Copyright (C) 2010 Monty Program Ab
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+/* Some defines to make it easier to use valgrind */
+
+#ifdef HAVE_valgrind
+#define IF_VALGRIND(A,B) (A)
+#else
+#define IF_VALGRIND(A,B) (B)
+#endif
+
+#if defined(HAVE_valgrind)&& defined(HAVE_VALGRIND_MEMCHECK_H)
+#include <valgrind/memcheck.h>
+#else
+#define VALGRIND_MAKE_MEM_DEFINED(addr, size) do { } while(0)
+#define VALGRIND_MAKE_MEM_NOACCESS(addr, size) do { } while(0)
+#ifdef SAFEMALLOC
+#define VALGRIND_MAKE_MEM_UNDEFINED(addr, size) bfill(addr, size, 0x8F)
+#else
+#define VALGRIND_MAKE_MEM_UNDEFINED(addr, size) do { } while(0)
+#endif /* SAFEMALLOC */
+#endif /* HAVE_valgrind */
+
+/* Compatibility with old source */
+#define TRASH(A,B) VALGRIND_MAKE_MEM_UNDEFINED(A, B)
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 32fc75fc692..8d3bc0c3fb2 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -21,7 +21,6 @@
#undef EXTRA_DEBUG
#define EXTRA_DEBUG
-
/*
Initialize memory root
@@ -276,7 +275,7 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
DBUG_RETURN((void*) start);
}
-#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
+#define TRASH_MEM(X) VALGRIND_MAKE_MEM_UNDEFINED(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
/* Mark all data in blocks free for reusage */