From 393ceeb915503e25b65fbba6becb0d05c14c9062 Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Fri, 17 Apr 2009 17:03:49 +0000 Subject: [PATCH] plug a memory leak in slurmd (leak generated only once at daemon startup) --- src/slurmd/common/setproctitle.c | 18 +++++++++++++++++- src/slurmd/common/setproctitle.h | 1 + src/slurmd/slurmd/slurmd.c | 5 ++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/slurmd/common/setproctitle.c b/src/slurmd/common/setproctitle.c index 63a6c1c38e9..977744fa775 100644 --- a/src/slurmd/common/setproctitle.c +++ b/src/slurmd/common/setproctitle.c @@ -2,7 +2,8 @@ * src/slurmd/common/setproctitle.c - argv manipulation * $Id$ ***************************************************************************** - * Copyright (C) 2002 The Regents of the University of California. + * Copyright (C) 2002-2007 The Regents of the University of California. + * Copyright (C) 2008-2009 Lawrence Livermore National Security. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Mark Grondona <mgrondona@llnl.gov>. * CODE-OCEC-09-009. All rights reserved. @@ -308,3 +309,18 @@ init_setproctitle(int argc, char *argv[]) #endif /* PS_USE_CLOBBER_ARGV */ } +/* Free memory allocated by init_setproctitle. + * Used to verify that all allocated memory gets freed */ +void fini_setproctitle(void) +{ +#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV + int i; + + for (i = 0; environ[i] != NULL; i++) { + free(environ[i]); + } + free(environ); + environ = (char **) NULL; +#endif /* PS_USE_CLOBBER_ARGV */ +} + diff --git a/src/slurmd/common/setproctitle.h b/src/slurmd/common/setproctitle.h index 8bfd2454f13..fb6f6aeb80a 100644 --- a/src/slurmd/common/setproctitle.h +++ b/src/slurmd/common/setproctitle.h @@ -47,6 +47,7 @@ #ifndef HAVE_SETPROCTITLE void setproctitle(const char *fmt, ...); void init_setproctitle(int argc, char *argv[]); +void fini_setproctitle(void); #endif #endif /* _BSD_SETPROCTITLE_H */ diff --git a/src/slurmd/slurmd/slurmd.c b/src/slurmd/slurmd/slurmd.c index aaa1ed0b469..fee4222b030 100644 --- a/src/slurmd/slurmd/slurmd.c +++ b/src/slurmd/slurmd/slurmd.c @@ -1078,9 +1078,7 @@ cleanup: * Then exercise the slurmd functionality before executing * > scontrol shutdown * - * There should be some definitely lost records from - * init_setproctitle (setproctitle.c), but it should otherwise account - * for all memory. + * All allocated memory should be freed \**************************************************************************/ static int _slurmd_fini() @@ -1093,6 +1091,7 @@ _slurmd_fini() slurm_proctrack_fini(); slurm_auth_fini(); slurmd_req(NULL); /* purge memory allocated by slurmd_req() */ + fini_setproctitle(); return SLURM_SUCCESS; } -- GitLab