From 41d6ddf5fbd287ad5d5a7ba44a2dfb82db4461fd Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 19 Aug 2012 17:50:37 +0200 Subject: [PATCH] mplayer: enable talloc leak report if special environment is variable set The functionality enabled with the --leak-report option is very useful for debugging. Introduce a check for the MPLAYER_LEAK_REPORT environment variable, and enable talloc leak report if it's set to "1". The environment variable encourages enabling leak report permanently during development. It's also a bit harder to get wrong: if the --leak-report option is not the first option, it's silently ignored. You can't put this option into a config file either. Enabling this with --enable-debug in configure is not an option, because the leak report code doesn't seem to be thread-safe, and thus is a bit dangerous. Also, move the code to the very beginning to make sure leak report is enabled before any other talloc function is used. Otherwise, these allocations could be missed. --- mplayer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mplayer.c b/mplayer.c index 963d505637..48758b2967 100644 --- a/mplayer.c +++ b/mplayer.c @@ -3861,6 +3861,13 @@ static void detach_ptw32(void) static void osdep_preinit(int *p_argc, char ***p_argv) { + char *enable_talloc = getenv("MPLAYER_LEAK_REPORT"); + if (*p_argc > 1 && (strcmp((*p_argv)[1], "-leak-report") == 0 + || strcmp((*p_argv)[1], "--leak-report") == 0)) + enable_talloc = "1"; + if (enable_talloc && strcmp(enable_talloc, "1") == 0) + talloc_enable_leak_report(); + GetCpuCaps(&gCpuCaps); #ifdef __MINGW32__ @@ -3900,10 +3907,6 @@ int main(int argc, char *argv[]) argv++; } - if (argc > 0 && (!strcmp(argv[0], "-leak-report") - || !strcmp(argv[0], "--leak-report"))) - talloc_enable_leak_report(); - struct MPContext *mpctx = talloc(NULL, MPContext); *mpctx = (struct MPContext){ .osd_function = OSD_PLAY,