From: Martin Quinson Date: Wed, 17 Oct 2012 21:36:34 +0000 (+0200) Subject: plug some memleaks in that example X-Git-Tag: v3_8~32^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3da9f0ae7a6c122de59a8a9f7d9589e237195cd7 plug some memleaks in that example This induce using static memory for the processes that are forcefully stopped, preventing the end of their main to get executed. --- diff --git a/examples/msg/cloud/masterslave_virtual_machines.c b/examples/msg/cloud/masterslave_virtual_machines.c index b0a073a2fb..bfbc81f6af 100644 --- a/examples/msg/cloud/masterslave_virtual_machines.c +++ b/examples/msg/cloud/masterslave_virtual_machines.c @@ -144,12 +144,12 @@ int master(int argc, char *argv[]) { /** Receiver function */ int slave_fun(int argc, char *argv[]) { - char *mailbox_name; + char mailbox_name[128]; msg_task_t task = NULL; _XBT_GNUC_UNUSED int res; /* since the slaves will move around, use slave_%d as mailbox names instead of hostnames */ xbt_assert(argc>=2, "slave processes need to be given their rank as parameter"); - mailbox_name=bprintf("Slave_%s",argv[1]); + sprintf(mailbox_name,"Slave_%s",argv[1]); XBT_INFO("Slave listenning on %s",argv[1]); while (1) { res = MSG_task_receive(&(task),mailbox_name); @@ -167,7 +167,6 @@ int slave_fun(int argc, char *argv[]) task = NULL; } - free(mailbox_name); return 0; } /* end_of_slave */ @@ -213,6 +212,8 @@ int main(int argc, char *argv[]) XBT_INFO("Simulation time %g", MSG_get_clock()); free(hosts); + for (i=0;i<10;i++) + free(hostnames[i]); free(hostnames); xbt_dynar_free(&hosts_dynar);