Skip to content
Snippets Groups Projects
Commit bbe63594 authored by Moe Jette's avatar Moe Jette
Browse files

Assortment of minor mods to eliminate all memory leaks and use of

 uninitialized variables (thanks to valgrind).
parent cb266881
Branches
No related tags found
No related merge requests found
Showing
with 196 additions and 68 deletions
......@@ -210,13 +210,18 @@ checkpoint_init(char *checkpoint_type)
}
/* shutdown checkpoint plugin */
extern void
extern int
checkpoint_fini(void)
{
int rc;
if ( !g_context )
return SLURM_SUCCESS;
slurm_mutex_lock( &context_lock );
if ( g_context )
_slurm_checkpoint_context_destroy(g_context);
rc =_slurm_checkpoint_context_destroy(g_context);
slurm_mutex_unlock( &context_lock );
return rc;
}
......
......
......@@ -56,7 +56,7 @@ typedef struct slurm_checkpoint_context * slurm_checkpoint_context_t;
extern int checkpoint_init(char *checkpoint_type);
/* shutdown checkpoint plugin */
extern void checkpoint_fini(void);
extern int checkpoint_fini(void);
/* perform some checkpoint operation */
extern int checkpoint_op(uint16_t op, uint16_t data,
......
......
......@@ -56,7 +56,6 @@
*/
typedef struct slurm_select_ops {
int (*fini) ( void );
int (*state_save) ( char *dir_name );
int (*state_restore) ( char *dir_name );
int (*node_init) ( struct node_record *node_ptr,
......@@ -110,7 +109,6 @@ static slurm_select_ops_t * _select_get_ops(slurm_select_context_t *c)
* Must be synchronized with slurm_select_ops_t above.
*/
static const char *syms[] = {
"fini",
"select_p_state_save",
"select_p_state_restore",
"select_p_node_init",
......@@ -236,10 +234,14 @@ extern int slurm_select_init(void)
extern int slurm_select_fini(void)
{
if (slurm_select_init() < 0)
return SLURM_ERROR;
int rc;
if (!g_select_context)
return SLURM_SUCCESS;
return (*(g_select_context->ops.fini))();
rc = _select_context_destroy( g_select_context );
g_select_context = NULL;
return rc;
}
/*
......@@ -410,6 +412,8 @@ extern int select_g_set_jobinfo (select_jobinfo_t jobinfo,
jobinfo->conn_type = *tmp_16;
break;
case SELECT_DATA_PART_ID:
/* we xfree() any preset value to avoid a memory leak */
xfree(jobinfo->bgl_part_id);
jobinfo->bgl_part_id = xstrdup(tmp_char);
break;
default:
......
......
......@@ -141,8 +141,8 @@ plugrack_entry_destructor( void *v )
* which should only be callable from plugrack_destroy().
*/
xassert( victim->refcount == 0 );
if ( victim->full_type ) xfree( victim->full_type );
if ( victim->fq_path ) xfree( victim->fq_path );
xfree( victim->full_type );
xfree( victim->fq_path );
if ( victim->plug != PLUGIN_INVALID_HANDLE )
plugin_unload( victim->plug );
xfree( victim );
......@@ -178,7 +178,8 @@ accept_path_paranoia( plugrack_t rack,
/* Is path owned by authorized user? */
if ( check_own ) {
if ( st.st_uid != rack->uid ) {
debug3( "accept_path_paranoia: %s not owned by proper user", fq_path );
debug3( "accept_path_paranoia: %s not owned by "
"proper user", fq_path );
return 0;
}
}
......@@ -187,7 +188,8 @@ accept_path_paranoia( plugrack_t rack,
if ( check_write ) {
if ( ( st.st_mode & S_IWGRP )
|| ( st.st_mode & S_IWOTH ) ) {
debug3( "accept_path_paranoia: %s writable by others", fq_path );
debug3( "accept_path_paranoia: %s writable by others",
fq_path );
return 0;
}
}
......@@ -323,7 +325,8 @@ plugrack_destroy( plugrack_t rack )
it = list_iterator_create( rack->entries );
while ( ( e = list_next( it ) ) != NULL ) {
if ( e->refcount > 0 ) {
debug2( "plugrack_destroy: attempt to destroy plugin rack that is still in use" );
debug2( "plugrack_destroy: attempt to destroy "
"plugin rack that is still in use" );
list_iterator_destroy( it );
return SLURM_ERROR; /* plugins still in use. */
}
......@@ -552,7 +555,8 @@ _plugrack_read_single_dir( plugrack_t rack, char *dir )
PLUGRACK_PARANOIA_FILE_OWN,
rack->paranoia &
PLUGRACK_PARANOIA_FILE_WRITABLE )) {
debug3( "plugin_read_dir: skipping %s for security reasons", fq_path );
debug3( "plugin_read_dir: skipping %s for security "
"reasons", fq_path );
continue;
}
......
......
......@@ -3,7 +3,7 @@
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by AUTHOR <AUTHOR@llnl.gov>.
* Written by Jay Windley <jwindley@lnxi.com>.
* UCRL-CODE-2002-040.
*
* This file is part of SLURM, a resource management program.
......
......
......@@ -254,8 +254,8 @@ slurm_auth_generic_errstr( int slurm_errno )
}
int
slurm_auth_context_destroy( slurm_auth_context_t c )
static int
_slurm_auth_context_destroy( slurm_auth_context_t c )
{
/*
* Must check return code here because plugins might still
......@@ -303,7 +303,7 @@ slurm_auth_init( void )
if ( slurm_auth_get_ops( g_context ) == NULL ) {
error( "cannot resolve %s plugin operations",
auth_type );
slurm_auth_context_destroy( g_context );
_slurm_auth_context_destroy( g_context );
g_context = NULL;
retval = SLURM_ERROR;
}
......@@ -314,6 +314,18 @@ slurm_auth_init( void )
return retval;
}
/* Release all global memory associated with the plugin */
extern int
slurm_auth_fini( void )
{
int rc;
if ( !g_context )
return SLURM_SUCCESS;
rc = _slurm_auth_context_destroy( g_context );
return rc;
}
/*
* Static bindings for the global authentication context. The test
......
......
......@@ -126,18 +126,23 @@ int slurm_auth_context_destroy( slurm_auth_context_t ctxt );
/*
* Prepare the global context.
*/
int slurm_auth_init( void );
extern int slurm_auth_init( void );
/*
* Destroy global context, free memory.
*/
extern int slurm_auth_fini( void );
/*
* Static bindings for the global authentication context.
*/
void *g_slurm_auth_create( void *hosts, int timeout );
int g_slurm_auth_destroy( void *cred );
int g_slurm_auth_verify( void *cred, void *hosts, int timeout );
uid_t g_slurm_auth_get_uid( void *cred );
gid_t g_slurm_auth_get_gid( void *cred );
int g_slurm_auth_pack( void *cred, Buf buf );
void *g_slurm_auth_unpack( Buf buf );
extern void *g_slurm_auth_create( void *hosts, int timeout );
extern int g_slurm_auth_destroy( void *cred );
extern int g_slurm_auth_verify( void *cred, void *hosts, int timeout );
extern uid_t g_slurm_auth_get_uid( void *cred );
extern gid_t g_slurm_auth_get_gid( void *cred );
extern int g_slurm_auth_pack( void *cred, Buf buf );
extern void *g_slurm_auth_unpack( Buf buf );
int g_slurm_auth_print( void *cred, FILE *fp );
int g_slurm_auth_errno( void *cred );
const char *g_slurm_auth_errstr( int slurm_errno );
......
......
......@@ -208,6 +208,19 @@ g_slurm_jobcomp_init( char *jobcomp_loc )
return retval;
}
extern int
g_slurm_jobcomp_fini(void)
{
int rc;
if ( !g_context)
return SLURM_SUCCESS;
rc = _slurm_jobcomp_context_destroy ( g_context );
g_context = NULL;
return SLURM_SUCCESS;
}
extern int
g_slurm_jobcomp_write(struct job_record *job_ptr)
{
......
......
......@@ -4,7 +4,7 @@
*****************************************************************************
* Copyright (C) 2003 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Moe Jette <jette@llnl.com> et. al.
* Written by Morris Jette <jette1@llnl.com> et. al.
* UCRL-CODE-2002-040.
*
* This file is part of SLURM, a resource management program.
......@@ -28,6 +28,9 @@
#ifndef __SLURM_JOBCOMP_H__
#define __SLURM_JOBCOMP_H__
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_STDINT_H
# include <stdint.h> /* for uint16_t, uint32_t definitions */
#endif
......@@ -45,6 +48,9 @@ typedef struct slurm_jobcomp_context * slurm_jobcomp_context_t;
/* initialization of job completion logging */
extern int g_slurm_jobcomp_init(char *jobcomp_loc);
/* terminate pthreads and free, general clean-up for termination */
extern int g_slurm_jobcomp_fini(void);
/* write record of a job's completion */
extern int g_slurm_jobcomp_write(struct job_record *job_ptr);
......
......
......@@ -123,15 +123,18 @@ int slurm_api_set_default_config()
static time_t last_config_update = (time_t) 0;
slurm_mutex_lock(&config_lock);
if ( (slurmctld_conf.slurm_conf) &&
(stat(slurmctld_conf.slurm_conf, &config_stat) < 0)) {
if (slurmctld_conf.slurm_conf
&& (stat(slurmctld_conf.slurm_conf, &config_stat) < 0)) {
error("Can't stat %s: %m", slurmctld_conf.slurm_conf);
rc = SLURM_ERROR;
goto cleanup;
}
if ((last_config_update == config_stat.st_mtime) &&
(slurmctld_conf.control_addr != NULL) &&
(slurmctld_conf.slurmctld_port != 0))
if (last_config_update
&& (slurmctld_conf.slurm_conf
&& (last_config_update == config_stat.st_mtime))
&& slurmctld_conf.control_addr
&& slurmctld_conf.slurmctld_port)
goto cleanup;
last_config_update = config_stat.st_mtime;
......
......
......@@ -44,6 +44,7 @@
* at the end of the structure.
*/
typedef struct slurm_switch_ops {
int (*fini) ( void );
int (*state_save) ( char *dir_name );
int (*state_restore) ( char *dir_name );
bool (*no_frag) ( void );
......@@ -103,6 +104,7 @@ struct slurm_switch_context {
static slurm_switch_context_t g_context = NULL;
static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
static slurm_switch_context_t
_slurm_switch_context_create( const char *switch_type)
{
......@@ -162,6 +164,7 @@ _slurm_switch_get_ops( slurm_switch_context_t c )
* declared for slurm_switch_ops_t.
*/
static const char *syms[] = {
"fini",
"switch_p_libstate_save",
"switch_p_libstate_restore",
"switch_p_no_frag",
......@@ -262,6 +265,17 @@ extern int switch_init( void )
return retval;
}
extern int switch_fini(void)
{
int rc;
if (!g_context)
return SLURM_SUCCESS;
rc = _slurm_switch_context_destroy(g_context);
return rc;
}
extern int switch_save(char *dir_name)
{
if ( switch_init() < 0 )
......
......
......@@ -56,6 +56,9 @@ typedef struct slurm_switch_context * slurm_switch_context_t;
/* initialize the switch plugin */
extern int switch_init (void);
/* terminate the switch plugin and free all memory */
extern int switch_fini (void);
/* save any global switch state to a file within the specified directory
* the actual file name used in plugin specific
* IN dir_name - directory into which switch state is saved
......
......
......@@ -102,6 +102,10 @@ int init( void )
return SLURM_SUCCESS;
}
extern int fini ( void )
{
return SLURM_SUCCESS;
}
slurm_auth_credential_t *
slurm_auth_create( void *argv[] )
......
......
......@@ -128,6 +128,11 @@ int init ( void )
return SLURM_SUCCESS;
}
extern int fini ( void )
{
return SLURM_SUCCESS;
}
/*
* Allocate a credential. This function should return NULL if it cannot
......
......
......@@ -142,12 +142,17 @@ enum {
* init() is called when the plugin is loaded, before any other functions
* are called. Put global initialization here.
*/
int init ( void )
extern int init ( void )
{
verbose("%s loaded", plugin_name);
return SLURM_SUCCESS;
}
extern int fini ( void )
{
return SLURM_SUCCESS;
}
/*
* The remainder of this file implements the standard SLURM authentication
* API.
......
......
......@@ -93,8 +93,7 @@ static char * script = NULL;
static char error_str[256];
static List job_list = NULL;
static pthread_t script_thread;
static bool thread_running = false;
static pthread_t script_thread = 0;
static pthread_mutex_t thread_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t job_list_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t job_list_cond = PTHREAD_COND_INITIALIZER;
......@@ -370,7 +369,7 @@ int init ( void )
return SLURM_ERROR;
}
if (thread_running) {
if (script_thread) {
debug2( "Script thread already running, not starting another");
pthread_mutex_unlock(&thread_flag_mutex);
return SLURM_ERROR;
......@@ -378,7 +377,6 @@ int init ( void )
slurm_attr_init(&attr);
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
pthread_create(&script_thread, &attr, script_agent, NULL);
thread_running = true;
pthread_mutex_unlock(&thread_flag_mutex);
......@@ -445,14 +443,26 @@ char *slurm_jobcomp_strerror( int errnum )
return error_str;
}
static void _cancel_thread (pthread_t thread_id)
{
int i;
for (i=0; i<4; i++) {
if (pthread_cancel(thread_id))
return;
usleep(1000);
}
error("Could not kill jobcomp script pthread");
}
/* Called when script unloads */
int fini ( void )
{
pthread_mutex_lock(&thread_flag_mutex);
if(thread_running) {
if(script_thread) {
verbose("Script Job Completion plugin shutting down");
pthread_cancel(script_thread);
thread_running = false;
_cancel_thread(script_thread);
script_thread = 0;
}
pthread_mutex_unlock(&thread_flag_mutex);
......
......
......@@ -28,6 +28,7 @@
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <slurm/slurm_errno.h>
#include "src/common/plugin.h"
......@@ -42,8 +43,7 @@ const uint32_t plugin_version = 90;
/* A plugin-global errno. */
static int plugin_errno = SLURM_SUCCESS;
static pthread_t backfill_thread;
static bool thread_running = false;
static pthread_t backfill_thread = 0;
static pthread_mutex_t thread_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
/**************************************************************************/
......@@ -65,7 +65,7 @@ int init( void )
verbose( "Backfill scheduler plugin loaded" );
pthread_mutex_lock( &thread_flag_mutex );
if ( thread_running ) {
if ( backfill_thread ) {
debug2( "Backfill thread already running, not starting another" );
pthread_mutex_unlock( &thread_flag_mutex );
return SLURM_ERROR;
......@@ -74,23 +74,33 @@ int init( void )
slurm_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
pthread_create( &backfill_thread, &attr, backfill_agent, NULL);
thread_running = true;
pthread_mutex_unlock( &thread_flag_mutex );
return SLURM_SUCCESS;
#endif
return SLURM_SUCCESS;
}
/**************************************************************************/
/* TAG( fini ) */
/**************************************************************************/
static void _cancel_thread (pthread_t thread_id)
{
int i;
for (i=0; i<4; i++) {
if (pthread_cancel(thread_id))
return;
usleep(1000);
}
error("Could not kill backfill sched pthread");
}
void fini( void )
{
pthread_mutex_lock( &thread_flag_mutex );
if ( thread_running ) {
if ( backfill_thread ) {
verbose( "Backfill scheduler plugin shutting down" );
pthread_cancel( backfill_thread );
thread_running = false;
_cancel_thread( backfill_thread );
backfill_thread = false;
}
pthread_mutex_unlock( &thread_flag_mutex );
}
......
......
......@@ -530,8 +530,14 @@ extern int init_bgl(void)
/* Purge all plugin variables */
extern void fini_bgl(void)
{
if (bgl_list) {
list_destroy(bgl_list);
bgl_list = NULL;
}
if (bgl_conf_list) {
list_destroy(bgl_conf_list);
bgl_conf_list = NULL;
}
}
extern void print_bgl_record(bgl_record_t* record)
......
......
......@@ -79,8 +79,7 @@ const char plugin_type[] = "select/bluegene";
const uint32_t plugin_version = 90;
/** pthread stuff for updating BGL node status */
static pthread_t bluegene_thread;
static bool thread_running = false;
static pthread_t bluegene_thread = 0;
static pthread_mutex_t thread_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
/** initialize the status pthread */
......@@ -112,7 +111,7 @@ static int _init_status_pthread()
pthread_attr_t attr;
pthread_mutex_lock( &thread_flag_mutex );
if ( thread_running ) {
if ( bluegene_thread ) {
debug2( "Bluegene thread already running, not starting another" );
pthread_mutex_unlock( &thread_flag_mutex );
return SLURM_ERROR;
......@@ -121,20 +120,31 @@ static int _init_status_pthread()
slurm_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
pthread_create( &bluegene_thread, &attr, bluegene_agent, NULL);
thread_running = true;
pthread_mutex_unlock( &thread_flag_mutex );
pthread_attr_destroy( &attr );
return SLURM_SUCCESS;
}
static void _cancel_thread (pthread_t thread_id)
{
int i;
for (i=0; i<4; i++) {
if (pthread_cancel(thread_id))
return;
usleep(1000);
}
error("Could not kill bluegene select pthread");
}
extern int fini ( void )
{
pthread_mutex_lock( &thread_flag_mutex );
if ( thread_running ) {
if ( bluegene_thread ) {
verbose( "Bluegene select plugin shutting down" );
pthread_cancel( bluegene_thread );
thread_running = false;
_cancel_thread( bluegene_thread );
bluegene_thread = 0;
}
pthread_mutex_unlock( &thread_flag_mutex );
......
......
......@@ -55,7 +55,7 @@ static int _set_elan_ids(void);
static void *_neterr_thr(void *arg);
static int neterr_retval = 0;
static pthread_t neterr_tid;
static pthread_t neterr_tid = 0;
static pthread_mutex_t neterr_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t neterr_cond = PTHREAD_COND_INITIALIZER;
......@@ -530,13 +530,22 @@ static void *_neterr_thr(void *arg)
* We don't really need to do anything special for Elan, but
* we'll call pthread_cancel() on the neterr resolver thread anyhow.
*/
int switch_p_node_fini ( void )
extern int switch_p_node_fini ( void )
{
#if HAVE_LIBELAN3
if (pthread_cancel(neterr_tid) == 0)
int i;
if (!neterr_tid)
return SLURM_SUCCESS;
error("Unable to cancel neterr thread: %m");
for (i=0; i<4; i++) {
if (pthread_cancel(neterr_tid)) {
neterr_tid = 0;
return SLURM_SUCCESS;
}
usleep(1000);
}
error("Could not kill switch elan pthread");
return SLURM_ERROR;
#else /* !HAVE_LIBELAN3 */
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment