* v2 talloc leak report
@ 2012-12-26 21:58 david
2012-12-26 21:58 ` [Patch v2 1/4] CLI: add talloc leak report, controlled by an environment variable david
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: david @ 2012-12-26 21:58 UTC (permalink / raw)
To: notmuch
Obsoletes
id:1355714648-23144-1-git-send-email-david@tethera.netZ
[Patch v2 1/4] CLI: add talloc leak report, controlled by an
- comments and formatting
[Patch v2 2/4] util: add talloc-extra.[ch]
- rename, fix dangerous memcpy
[Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup
no change, except new names
[Patch v2 4/4] perf-test: initial support for talloc leak report in
New patch, use talloc reports in memory tests.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Patch v2 1/4] CLI: add talloc leak report, controlled by an environment variable.
2012-12-26 21:58 v2 talloc leak report david
@ 2012-12-26 21:58 ` david
2012-12-26 21:58 ` [Patch v2 2/4] util: add talloc-extra.[ch] david
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: david @ 2012-12-26 21:58 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
From: David Bremner <bremner@debian.org>
The argument handling in notmuch.c seems due for an overhaul, but
until then use an environment variable to specify a location to write
the talloc leak report to. This is only enabled for the (interesting)
case where some notmuch subcommand is invoked.
---
notmuch.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/notmuch.c b/notmuch.c
index ee2892e..6b7aae8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -321,8 +321,28 @@ main (int argc, char *argv[])
for (i = 0; i < ARRAY_SIZE (commands); i++) {
command = &commands[i];
- if (strcmp (argv[1], command->name) == 0)
- return (command->function)(local, argc - 1, &argv[1]);
+ if (strcmp (argv[1], command->name) == 0) {
+ int ret;
+ char *talloc_report;
+
+ ret = (command->function)(local, argc - 1, &argv[1]);
+
+ /* in the future support for this environment variable may
+ * be supplemented or replaced by command line arguments
+ * --leak-report and/or --leak-report-full */
+
+ talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
+
+ /* this relies on the previous call to
+ * talloc_enable_null_tracking */
+
+ if (talloc_report && strcmp (talloc_report, "") != 0) {
+ FILE *report = fopen (talloc_report, "w");
+ talloc_report_full (NULL, report);
+ }
+
+ return ret;
+ }
}
fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Patch v2 2/4] util: add talloc-extra.[ch]
2012-12-26 21:58 v2 talloc leak report david
2012-12-26 21:58 ` [Patch v2 1/4] CLI: add talloc leak report, controlled by an environment variable david
@ 2012-12-26 21:58 ` david
2012-12-26 21:58 ` [Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup david
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: david @ 2012-12-26 21:58 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
From: David Bremner <bremner@debian.org>
These are intended to be simple wrappers to provide slightly better
debugging information than what talloc currently provides natively.
---
notmuch-client.h | 2 +-
util/Makefile.local | 2 +-
| 14 ++++++++++++++
| 18 ++++++++++++++++++
4 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 util/talloc-extra.c
create mode 100644 util/talloc-extra.h
diff --git a/notmuch-client.h b/notmuch-client.h
index d7b352e..5f28836 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -58,7 +58,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
#include <errno.h>
#include <signal.h>
-#include <talloc.h>
+#include "talloc-extra.h"
#define unused(x) x __attribute__ ((unused))
diff --git a/util/Makefile.local b/util/Makefile.local
index a11e35b..29c0ce6 100644
--- a/util/Makefile.local
+++ b/util/Makefile.local
@@ -4,7 +4,7 @@ dir := util
extra_cflags += -I$(srcdir)/$(dir)
libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
- $(dir)/string-util.c
+ $(dir)/string-util.c $(dir)/talloc-extra.c
libutil_modules := $(libutil_c_srcs:.c=.o)
--git a/util/talloc-extra.c b/util/talloc-extra.c
new file mode 100644
index 0000000..4a5f9c0
--- /dev/null
+++ b/util/talloc-extra.c
@@ -0,0 +1,14 @@
+#include <string.h>
+#include "talloc-extra.h"
+
+char *
+talloc_strndup_named_const (void *ctx, const char *str,
+ size_t len, const char *name)
+{
+ char *ptr = talloc_strndup (ctx, str, len);
+
+ if (ptr)
+ talloc_set_name_const(ptr, name);
+
+ return ptr;
+}
--git a/util/talloc-extra.h b/util/talloc-extra.h
new file mode 100644
index 0000000..5b8ca28
--- /dev/null
+++ b/util/talloc-extra.h
@@ -0,0 +1,18 @@
+#ifndef _XTALLOC_H
+#define _XTALLOC_H
+
+#include <talloc.h>
+
+/* Like talloc_strndup, but take an extra parameter for the internal talloc
+ * name (for debugging) */
+
+char *
+talloc_strndup_named_const (void *ctx, const char *str,
+ size_t len, const char *name);
+
+/* use the __location__ macro from talloc.h to name a string according to its
+ * source location */
+
+#define talloc_strndup_debug(ctx, str, len) talloc_strndup_named_const (ctx, str, len, __location__)
+
+#endif
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup
2012-12-26 21:58 v2 talloc leak report david
2012-12-26 21:58 ` [Patch v2 1/4] CLI: add talloc leak report, controlled by an environment variable david
2012-12-26 21:58 ` [Patch v2 2/4] util: add talloc-extra.[ch] david
@ 2012-12-26 21:58 ` david
2012-12-26 21:58 ` [Patch v2 4/4] perf-test: initial support for talloc leak report in memory tests david
2012-12-27 17:13 ` v2 talloc leak report Tomi Ollila
4 siblings, 0 replies; 7+ messages in thread
From: david @ 2012-12-26 21:58 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
From: David Bremner <bremner@debian.org>
This gives line numbers for better debugging.
---
notmuch-restore.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/notmuch-restore.c b/notmuch-restore.c
index c93f1ac..6111977 100644
--- a/notmuch-restore.c
+++ b/notmuch-restore.c
@@ -88,10 +88,11 @@ parse_sup_line (void *ctx, char *line,
return 1;
}
- *query_str = talloc_strndup (ctx, line + match[1].rm_so,
- match[1].rm_eo - match[1].rm_so);
- file_tags = talloc_strndup (ctx, line + match[2].rm_so,
- match[2].rm_eo - match[2].rm_so);
+ *query_str = talloc_strndup_debug (ctx, line + match[1].rm_so,
+ match[1].rm_eo - match[1].rm_so);
+
+ file_tags = talloc_strndup_debug (ctx, line + match[2].rm_so,
+ match[2].rm_eo - match[2].rm_so);
char *tok = file_tags;
size_t tok_len = 0;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Patch v2 4/4] perf-test: initial support for talloc leak report in memory tests
2012-12-26 21:58 v2 talloc leak report david
` (2 preceding siblings ...)
2012-12-26 21:58 ` [Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup david
@ 2012-12-26 21:58 ` david
2012-12-27 17:13 ` v2 talloc leak report Tomi Ollila
4 siblings, 0 replies; 7+ messages in thread
From: david @ 2012-12-26 21:58 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
From: David Bremner <bremner@debian.org>
As with the valgrind logs, we print a (very) brief summary and leave
the log for inspection.
---
performance-test/perf-test-lib.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/performance-test/perf-test-lib.sh b/performance-test/perf-test-lib.sh
index 10d05e0..9ee7661 100644
--- a/performance-test/perf-test-lib.sh
+++ b/performance-test/perf-test-lib.sh
@@ -126,13 +126,16 @@ memory_run ()
test_count=$(($test_count+1))
log_file=$log_dir/$test_count.log
+ talloc_log=$log_dir/$test_count.talloc
printf "[ %d ]\t%s\n" $test_count "$1"
- valgrind --leak-check=full --log-file="$log_file" $2
+ NOTMUCH_TALLOC_REPORT="$talloc_log" valgrind --leak-check=full --log-file="$log_file" $2
awk '/LEAK SUMMARY/,/suppressed/ { sub(/^==[0-9]*==/," "); print }' "$log_file"
echo
+ sed -n -e 's/.*[(]total *\([^)]*\)[)]/talloced at exit: \1/p' $talloc_log
+ echo
}
memory_done ()
--
1.7.10.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: v2 talloc leak report
2012-12-26 21:58 v2 talloc leak report david
` (3 preceding siblings ...)
2012-12-26 21:58 ` [Patch v2 4/4] perf-test: initial support for talloc leak report in memory tests david
@ 2012-12-27 17:13 ` Tomi Ollila
2013-01-01 3:12 ` David Bremner
4 siblings, 1 reply; 7+ messages in thread
From: Tomi Ollila @ 2012-12-27 17:13 UTC (permalink / raw)
To: david, notmuch
On Wed, Dec 26 2012, david@tethera.net wrote:
> Obsoletes
>
> id:1355714648-23144-1-git-send-email-david@tethera.netZ
>
> [Patch v2 1/4] CLI: add talloc leak report, controlled by an
> - comments and formatting
>
> [Patch v2 2/4] util: add talloc-extra.[ch]
> - rename, fix dangerous memcpy
>
> [Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup
> no change, except new names
>
> [Patch v2 4/4] perf-test: initial support for talloc leak report in
> New patch, use talloc reports in memory tests.
This series LGTM ... if you care to amend s/_XTALLOC_H/_TALLOC_EXTRA_H/
Tomi
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: v2 talloc leak report
2012-12-27 17:13 ` v2 talloc leak report Tomi Ollila
@ 2013-01-01 3:12 ` David Bremner
0 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2013-01-01 3:12 UTC (permalink / raw)
To: Tomi Ollila, notmuch
Tomi Ollila <tomi.ollila@iki.fi> writes:
>
> This series LGTM ... if you care to amend s/_XTALLOC_H/_TALLOC_EXTRA_H/
>
amended and pushed,
d
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-01-01 3:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-26 21:58 v2 talloc leak report david
2012-12-26 21:58 ` [Patch v2 1/4] CLI: add talloc leak report, controlled by an environment variable david
2012-12-26 21:58 ` [Patch v2 2/4] util: add talloc-extra.[ch] david
2012-12-26 21:58 ` [Patch v2 3/4] notmuch-restore: use debug version of talloc_strndup david
2012-12-26 21:58 ` [Patch v2 4/4] perf-test: initial support for talloc leak report in memory tests david
2012-12-27 17:13 ` v2 talloc leak report Tomi Ollila
2013-01-01 3:12 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).