Browse Source

src,mpi/src: check return value for malloc/calloc/realloc functions

Nathalie Furmento 8 years ago
parent
commit
aef60c0c2d
5 changed files with 30 additions and 14 deletions
  1. 3 1
      mpi/src/starpu_mpi.c
  2. 4 2
      src/common/thread.c
  3. 13 5
      src/core/simgrid.c
  4. 1 1
      src/datawizard/malloc.c
  5. 9 5
      tools/starpu_tasks_rec_complete.c

+ 3 - 1
mpi/src/starpu_mpi.c

@@ -1327,7 +1327,9 @@ static void *_starpu_mpi_progress_thread_func(void *arg)
 	MSG_process_create_with_arguments("main", smpi_simulated_main_, NULL, _starpu_simgrid_get_host_by_name("MAIN"), *(argc_argv->argc), argv_cpy);
 	MSG_process_create_with_arguments("main", smpi_simulated_main_, NULL, _starpu_simgrid_get_host_by_name("MAIN"), *(argc_argv->argc), argv_cpy);
 	/* And set TSD for us */
 	/* And set TSD for us */
 #ifdef HAVE_SMPI_PROCESS_SET_USER_DATA
 #ifdef HAVE_SMPI_PROCESS_SET_USER_DATA
-	smpi_process_set_user_data(calloc(MAX_TSD + 1, sizeof(void*)));
+	void **tsd;
+	_STARPU_CALLOC(tsd, MAX_TSD + 1, sizeof(void*));
+	smpi_process_set_user_data(tsd);
 #endif
 #endif
 #endif
 #endif
 
 

+ 4 - 2
src/common/thread.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2010, 2012-2017  Université de Bordeaux
  * Copyright (C) 2010, 2012-2017  Université de Bordeaux
- * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
+ * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017  CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * it under the terms of the GNU Lesser General Public License as published by
@@ -57,7 +57,9 @@ int starpu_pthread_create_on(char *name, starpu_pthread_t *thread, const starpu_
 	_args[2] = NULL;
 	_args[2] = NULL;
 	if (!host)
 	if (!host)
 		host = MSG_get_host_by_name("MAIN");
 		host = MSG_get_host_by_name("MAIN");
-	*thread = MSG_process_create_with_arguments(name, _starpu_simgrid_thread_start, calloc(MAX_TSD+1, sizeof(void*)), host, 2, _args);
+	void *tsd;
+	_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
+	*thread = MSG_process_create_with_arguments(name, _starpu_simgrid_thread_start, tsd, host, 2, _args);
 	return 0;
 	return 0;
 }
 }
 
 

+ 13 - 5
src/core/simgrid.c

@@ -278,7 +278,9 @@ int main(int argc, char **argv)
 	int i;
 	int i;
 	for (i = 0; i < argc; i++)
 	for (i = 0; i < argc; i++)
 		argv_cpy[i] = strdup(argv[i]);
 		argv_cpy[i] = strdup(argv[i]);
-	MSG_process_create_with_arguments("main", &do_starpu_main, calloc(MAX_TSD+1, sizeof(void*)), MSG_get_host_by_name("MAIN"), argc, argv_cpy);
+	void **tsd;
+	_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
+	MSG_process_create_with_arguments("main", &do_starpu_main, tsd, MSG_get_host_by_name("MAIN"), argc, argv_cpy);
 
 
 	/* And run maestro in main thread */
 	/* And run maestro in main thread */
 	MSG_main();
 	MSG_main();
@@ -310,7 +312,9 @@ void _starpu_simgrid_init_early(int *argc STARPU_ATTRIBUTE_UNUSED, char ***argv
 		/* Initialize simgrid */
 		/* Initialize simgrid */
 		start_simgrid(argc, *argv);
 		start_simgrid(argc, *argv);
 		/* And attach the main thread to the main simgrid process */
 		/* And attach the main thread to the main simgrid process */
-		MSG_process_attach("main", calloc(MAX_TSD, sizeof(void*)), MSG_get_host_by_name("MAIN"), NULL);
+		void **tsd;
+		_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
+		MSG_process_attach("main", tsd, MSG_get_host_by_name("MAIN"), NULL);
 		simgrid_started = 2;
 		simgrid_started = 2;
 	}
 	}
 #endif
 #endif
@@ -324,7 +328,9 @@ void _starpu_simgrid_init_early(int *argc STARPU_ATTRIBUTE_UNUSED, char ***argv
 #ifndef STARPU_STATIC_ONLY
 #ifndef STARPU_STATIC_ONLY
 		_STARPU_ERROR("Simgrid currently does not support privatization for dynamically-linked libraries in SMPI. Please reconfigure and build StarPU with --disable-shared");
 		_STARPU_ERROR("Simgrid currently does not support privatization for dynamically-linked libraries in SMPI. Please reconfigure and build StarPU with --disable-shared");
 #endif
 #endif
-		MSG_process_set_data(MSG_process_self(), calloc(MAX_TSD, sizeof(void*)));
+		void **tsd;
+		_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
+		MSG_process_set_data(MSG_process_self(), tsd);
 	}
 	}
 	unsigned i;
 	unsigned i;
 	for (i = 0; i < STARPU_MAXNODES; i++)
 	for (i = 0; i < STARPU_MAXNODES; i++)
@@ -341,7 +347,8 @@ void _starpu_simgrid_init(void)
 	{
 	{
 		char s[32];
 		char s[32];
 		snprintf(s, sizeof(s), "worker %u runner", i);
 		snprintf(s, sizeof(s), "worker %u runner", i);
-		void **tsd = calloc(MAX_TSD+1, sizeof(void*));
+		void **tsd;
+		_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
 		worker_runner[i].sem = MSG_sem_init(0);
 		worker_runner[i].sem = MSG_sem_init(0);
 		tsd[0] = (void*)(uintptr_t) i;
 		tsd[0] = (void*)(uintptr_t) i;
 		worker_runner[i].runner = MSG_process_create_with_arguments(s, task_execute, tsd, _starpu_simgrid_get_host_by_worker(_starpu_get_worker_struct(i)), 0, NULL);
 		worker_runner[i].runner = MSG_process_create_with_arguments(s, task_execute, tsd, _starpu_simgrid_get_host_by_worker(_starpu_get_worker_struct(i)), 0, NULL);
@@ -629,7 +636,8 @@ static void transfer_queue(struct transfer *transfer)
 		{
 		{
 			char s[64];
 			char s[64];
 			snprintf(s, sizeof(s), "transfer %u-%u runner", src, dst);
 			snprintf(s, sizeof(s), "transfer %u-%u runner", src, dst);
-			void **tsd = calloc(MAX_TSD+1, sizeof(void*));
+			void **tsd;
+			_STARPU_CALLOC(tsd, MAX_TSD+1, sizeof(void*));
 			tsd[0] = (void*)(uintptr_t)((src<<16) + dst);
 			tsd[0] = (void*)(uintptr_t)((src<<16) + dst);
 			t->runner = MSG_process_create_with_arguments(s, transfer_execute, tsd, _starpu_simgrid_get_memnode_host(src), 0, NULL);
 			t->runner = MSG_process_create_with_arguments(s, transfer_execute, tsd, _starpu_simgrid_get_memnode_host(src), 0, NULL);
 			t->sem = MSG_sem_init(0);
 			t->sem = MSG_sem_init(0);

+ 1 - 1
src/datawizard/malloc.c

@@ -73,7 +73,7 @@ struct malloc_pinned_codelet_struct
 //static void malloc_pinned_opencl_codelet(void *buffers[] STARPU_ATTRIBUTE_UNUSED, void *arg)
 //static void malloc_pinned_opencl_codelet(void *buffers[] STARPU_ATTRIBUTE_UNUSED, void *arg)
 //{
 //{
 //	struct malloc_pinned_codelet_struct *s = arg;
 //	struct malloc_pinned_codelet_struct *s = arg;
-//        //        *(s->ptr) = malloc(s->dim);
+//        //        _STARPU_MALLOC(*(s->ptr), s->dim);
 //        starpu_opencl_allocate_memory(devid, (void **)(s->ptr), s->dim, CL_MEM_READ_WRITE|CL_MEM_ALLOC_HOST_PTR);
 //        starpu_opencl_allocate_memory(devid, (void **)(s->ptr), s->dim, CL_MEM_READ_WRITE|CL_MEM_ALLOC_HOST_PTR);
 //}
 //}
 //#endif
 //#endif

+ 9 - 5
tools/starpu_tasks_rec_complete.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  *
  * Copyright (C) 2011-2014, 2016  Universite de Bordeaux
  * Copyright (C) 2011-2014, 2016  Universite de Bordeaux
- * Copyright (C) 2012-2015  CNRS
+ * Copyright (C) 2012-2015, 2017  CNRS
  *
  *
  * StarPU is free software; you can redistribute it and/or modify
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
 #include <common/uthash.h>
 #include <common/uthash.h>
+#include <common/utils.h>
 #include <starpu.h>
 #include <starpu.h>
 
 
 #define PROGNAME "starpu_tasks_rec_complete"
 #define PROGNAME "starpu_tasks_rec_complete"
@@ -31,13 +32,15 @@
  * additional information, notably estimated termination times.
  * additional information, notably estimated termination times.
  */
  */
 
 
-static struct model {
+static struct model
+{
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 	char *name;
 	char *name;
 	struct starpu_perfmodel model;
 	struct starpu_perfmodel model;
 } *models;
 } *models;
 
 
-int main(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
 	FILE *input;
 	FILE *input;
 	FILE *output;
 	FILE *output;
 	char s[1024], *c;
 	char s[1024], *c;
@@ -47,7 +50,8 @@ int main(int argc, char *argv[]) {
 	struct model *model, *tmp;
 	struct model *model, *tmp;
 	int ret;
 	int ret;
 
 
-	if (argc >= 2) {
+	if (argc >= 2)
+	{
 		if (!strcmp(argv[1], "-h") ||
 		if (!strcmp(argv[1], "-h") ||
 		    !strcmp(argv[1], "--help"))
 		    !strcmp(argv[1], "--help"))
 		{
 		{
@@ -119,7 +123,7 @@ int main(int argc, char *argv[]) {
 					HASH_FIND_STR(models, model_name, model);
 					HASH_FIND_STR(models, model_name, model);
 					if (model == NULL)
 					if (model == NULL)
 					{
 					{
-						model = malloc(sizeof(*model));
+						_STARPU_MALLOC(model, sizeof(*model));
 						model->name = model_name;
 						model->name = model_name;
 						memset(&model->model, 0, sizeof(model->model));
 						memset(&model->model, 0, sizeof(model->model));
 						model->model.type = STARPU_PERFMODEL_INVALID;
 						model->model.type = STARPU_PERFMODEL_INVALID;