Browse Source

src/core/workers.*: use dynamic memory for default configuration

Nathalie Furmento 13 years ago
parent
commit
c58c88a302
2 changed files with 13 additions and 3 deletions
  1. 9 3
      src/core/workers.c
  2. 4 0
      src/core/workers.h

+ 9 - 3
src/core/workers.c

@@ -478,13 +478,15 @@ int starpu_init(struct starpu_conf *user_conf)
 	 * initialization */
 	if (user_conf == NULL)
 	{
-	     struct starpu_conf conf;
-	     starpu_conf_init(&conf);
-	     config.conf = &conf;
+	     struct starpu_conf *conf = malloc(sizeof(struct starpu_conf));
+	     starpu_conf_init(conf);
+	     config.conf = conf;
+	     config.default_conf = 1;
 	}
 	else
 	{
 	     config.conf = user_conf;
+	     config.default_conf = 0;
 	}
 	_starpu_conf_check_environment(config.conf);
 
@@ -679,6 +681,10 @@ void starpu_shutdown(void)
 	_STARPU_PTHREAD_COND_SIGNAL(&init_cond);
 	_STARPU_PTHREAD_MUTEX_UNLOCK(&init_mutex);
 
+	/* Clear memory if it was allocated by StarPU */
+	if (config.default_conf)
+	     free(config.conf);
+
 	_STARPU_DEBUG("Shutdown finished\n");
 }
 

+ 4 - 0
src/core/workers.h

@@ -153,6 +153,10 @@ struct _starpu_machine_config
 
         /* either the user given configuration passed to starpu_init or a default configuration */
 	struct starpu_conf *conf;
+	/* set to 1 if no conf has been given by the user, it
+	 * indicates the memory allocated for the default
+	 * configuration should be freed on shutdown */
+	int default_conf;
 
 	/* this flag is set until the runtime is stopped */
 	unsigned running;