From: Arnaud Giersch Date: Mon, 30 Oct 2017 07:41:57 +0000 (+0100) Subject: Remove useless allocations. X-Git-Tag: v3.18~347 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/12a28e1db519ea909c66f6be10ceb308f1333d14 Remove useless allocations. --- diff --git a/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c b/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c index 107179fe01..233b978a46 100644 --- a/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c +++ b/teshsuite/smpi/coll-alltoallv/coll-alltoallv.c @@ -44,7 +44,7 @@ <2> rbuf: (#9): [3][4][103][104][203][204][-1][-1][-1] */ -static void print_buffer_int(void *buf, int len, char *msg, int rank) +static void print_buffer_int(void *buf, int len, const char *msg, int rank) { printf("[%d] %s (#%d): ", rank, msg, len); for (int tmp = 0; tmp < len; tmp++) { @@ -52,7 +52,6 @@ static void print_buffer_int(void *buf, int len, char *msg, int rank) printf("[%d]", v[tmp]); } printf("\n"); - free(msg); } int main(int argc, char **argv) @@ -94,15 +93,15 @@ int main(int argc, char **argv) sdispls[i] = (i * (i + 1)) / 2; } - print_buffer_int( sbuf, size*size, strdup("sbuf:"),rank); - print_buffer_int( sendcounts, size, strdup("scount:"),rank); - print_buffer_int( recvcounts, size, strdup("rcount:"),rank); - print_buffer_int( sdispls, size, strdup("sdisp:"),rank); - print_buffer_int( rdispls, size, strdup("rdisp:"),rank); + print_buffer_int(sbuf, size * size, "sbuf:", rank); + print_buffer_int(sendcounts, size, "scount:", rank); + print_buffer_int(recvcounts, size, "rcount:", rank); + print_buffer_int(sdispls, size, "sdisp:", rank); + print_buffer_int(rdispls, size, "rdisp:", rank); MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, comm); - print_buffer_int( rbuf, size*size, strdup("rbuf:"),rank); + print_buffer_int(rbuf, size * size, "rbuf:", rank); MPI_Barrier(MPI_COMM_WORLD); if (0 == rank) { diff --git a/teshsuite/smpi/macro-shared/macro-shared.c b/teshsuite/smpi/macro-shared/macro-shared.c index 1e09ac43de..51da71b1d6 100644 --- a/teshsuite/smpi/macro-shared/macro-shared.c +++ b/teshsuite/smpi/macro-shared/macro-shared.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2015. The SimGrid Team. +/* Copyright (c) 2009-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -11,9 +11,9 @@ #include #include -static void* hash(char *str, uint64_t* ans) +static void* hash(const char *str, uint64_t* ans) { - char *tohash = str; + const char *tohash = str; *ans=5381; printf("hashing !\n"); int c = *tohash; @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) MPI_Barrier(MPI_COMM_WORLD); //Try SMPI_SHARED_CALL function, which should call hash only once and for all. - char *str = strdup("onceandforall"); + static const char str[] = "onceandforall"; if(rank==size-1){ SMPI_SHARED_CALL(hash,str,str,buf); } @@ -55,7 +55,6 @@ int main(int argc, char *argv[]) printf("[%d] After change, the value in the shared buffer is: %" PRIu64"\n", rank, *buf); SMPI_SHARED_FREE(buf); - free(str); MPI_Finalize(); return 0; diff --git a/teshsuite/xbt/parallel_log_crashtest/parallel_log_crashtest.c b/teshsuite/xbt/parallel_log_crashtest/parallel_log_crashtest.c index d904a1a43f..b51973990a 100644 --- a/teshsuite/xbt/parallel_log_crashtest/parallel_log_crashtest.c +++ b/teshsuite/xbt/parallel_log_crashtest/parallel_log_crashtest.c @@ -1,6 +1,6 @@ /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/ -/* Copyright (c) 2007-2014. The SimGrid Team. +/* Copyright (c) 2007-2017. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -43,9 +43,9 @@ static int crasher() /* spawn threads */ for (int i = 0; i < crasher_amount; i++) { - char *name = bprintf("thread %d", i); + char name[16]; + snprintf(name, sizeof name, "thread %d", i); crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL ); - free(name); } /* wait for them */