Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2006-11-07 16:32:48 +0000
committerAaron Griffin <aaron@archlinux.org>2006-11-07 16:32:48 +0000
commit34931106d7653e73bb474e1d72aee4044f7d5a5d (patch)
tree3363f88bf77b284af3424bed72e2cddc78ef1a41
parenta8e44ff00ad5dd2d3f59bdf4c024d94db3f23ae4 (diff)
Added mcheck support for memory debugging
-rw-r--r--configure.ac1
-rw-r--r--src/pacman/pacman.c35
2 files changed, 30 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index c7aac6c3..c87d17b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -319,6 +319,7 @@ AC_MSG_CHECKING(for debug mode request)
if test x$debug = xyes ; then
AM_CONDITIONAL(PACMAN_DEBUG, test x$debug = xyes)
CFLAGS="-g -Wall -Werror -std=c99 -DPACMAN_DEBUG"
+ LDFLAGS="$LDFLAGS -lmcheck"
AC_MSG_RESULT(yes)
else
AM_CONDITIONAL(PACMAN_DEBUG, test x$debug = xno)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 9259cf9d..1708d371 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -85,6 +85,32 @@ unsigned int maxcols = 80;
extern int neednl;
+#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD)
+void mcheck_abort(enum mcheck_status status)
+{
+ switch(status)
+ {
+ case MCHECK_DISABLED:
+ fputs("mcheck: disabled, no checking can be done", stderr);
+ break;
+ case MCHECK_OK:
+ fputs("mcheck: block ok", stderr);
+ break;
+ case MCHECK_HEAD:
+ fputs("mcheck: inconsistancy at block head (underrun)", stderr);
+ abort();
+ break;
+ case MCHECK_TAIL:
+ fputs("mcheck: inconsistancy at block tail (overrun)", stderr);
+ abort();
+ break;
+ case MCHECK_FREE:
+ fputs("mcheck: block has already been freed", stderr);
+ break;
+ };
+}
+#endif
+
/* Display usage/syntax for the specified operation.
* op: the operation code requested
* myname: basename(argv[0])
@@ -209,12 +235,10 @@ static void cleanup(int signum)
FREELIST(pm_targets);
FREECONF(config);
-#ifndef CYGWIN
-#ifndef BSD
+#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD)
/* debug */
muntrace();
#endif
-#endif
if(neednl) {
putchar('\n');
@@ -417,11 +441,10 @@ int main(int argc, char *argv[])
#endif
list_t *lp;
-#ifndef CYGWIN
-#ifndef BSD
+#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD)
/* debug */
mtrace();
-#endif
+ mcheck(0);
#endif
cenv = getenv("COLUMNS");