On Thursday 05 January 2012 15:36:47 Raphael Geissert wrote: > Apparently nobody had run valgrind on the collector for a long time and > there are lots of bugs, but those have been there for a long time. Will > probably address them by tomorrow and post a patch, so that if you have no > luck with the backtrace you can run it on valgrind and get a meaningful > output.
Attached is the patch. The only things that valgrind still complains about are some leaks[1] and the use of some uninitialized memory in auparse (which I'll try to investigate sts.) To run valgrind do something like: touch /.readahead_collect edit /etc/init.d/early-readahead to replace s-s-d's --exec $READAHEAD_COLLECT_CMD with --exec /usr/bin/valgrind -- --trace-children=yes --track-origins=yes $READAHEAD_COLLECT_CMD 2> /run/rac-valgrind.log [1]could fix them, but the program exits soon after leaking them Cheers, -- Raphael Geissert - Debian Developer www.debian.org - get.debian.net
diff --git a/src/readahead-collector.c b/src/readahead-collector.c index 0104c59..2fff27b 100644 --- a/src/readahead-collector.c +++ b/src/readahead-collector.c @@ -387,8 +387,10 @@ main(int argc, char **argv) debug("done: success"); - if (has_debug && is_background(rac) && debug_out != stderr) + if (has_debug && is_background(rac) && debug_out != stderr) { fclose(debug_out); + debug_out = 0; + } exit(EXIT_SUCCESS); } @@ -501,7 +503,7 @@ string_to_array(char *data) if (isspace((unsigned char) *l)) items--; if (items) - res = (char **) malloc(sizeof(char *) * items + 1); + res = (char **) malloc(sizeof(char *) * (items + 1)); if (!res) return NULL; p = data; @@ -1164,8 +1166,7 @@ myrealpath(const char *path, char *resolved_path, int maxreslth, const char *cwd char *npath; char link_path[PATH_MAX+1]; int n; - char *buf = NULL; - int bufsz = 0; + char *oldbuf = NULL; npath = resolved_path; @@ -1226,6 +1227,7 @@ myrealpath(const char *path, char *resolved_path, int maxreslth, const char *cwd goto err; } else { int m; + char *buf; /* Note: readlink doesn't add the null byte. */ link_path[n] = '\0'; @@ -1240,15 +1242,13 @@ myrealpath(const char *path, char *resolved_path, int maxreslth, const char *cwd /* Insert symlink contents into path. */ m = strlen(path); - if (!buf) - buf = malloc(m + n + 1); - else if (m + n + 1 > bufsz) - buf = realloc(buf, m + n + 1); - bufsz = m + n + 1; + buf = malloc(m + n + 1); memcpy(buf, link_path, n); memcpy(buf + n, path, m + 1); - path = buf; + free(oldbuf); + /* keep a copy of buf in oldbuf to free it later */ + path = oldbuf = buf; } *npath++ = '/'; } @@ -1258,12 +1258,10 @@ myrealpath(const char *path, char *resolved_path, int maxreslth, const char *cwd /* Make sure it's null terminated. */ *npath = '\0'; - if (buf) - free(buf); + free(oldbuf); return resolved_path; err: - if (buf) - free(buf); + free(oldbuf); return NULL; } @@ -1275,10 +1273,16 @@ exclude_file(char **list, const char *filename) { char **p = list; + if (*filename == '\0') + return 0; + for (; p && *p; p++) { const char *f = filename; char *e = *p; - while(*f++ == *e++); + for (; *f == *e; *f++, *e++) { + if (*e == '\0') + return 1; + } if (*e == '\0') return 1; }