From 2d05b6e5e8e3056fd43638e787609b0091bd3f15 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 30 Jun 2014 01:08:45 +0200 Subject: [PATCH] bugfix: Strdup the generated mac address --- Core/Config.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index d2eee39305..13869a3b41 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -241,14 +241,15 @@ const char *DefaultLangRegion() { const char *CreateRandMAC() { std::stringstream randStream; - srand(time(0)); - for(int i = 0; i < 6; i++) { - randStream << std::hex << (rand() % 256); //generates each octet for the mac in hex format - if (i<5) { - randStream << ':'; //we need a : between every octet - } - } - return randStream.str().c_str(); //no need for creating a new string, just return this + srand(time(0)); + for(int i = 0; i < 6; i++) { + randStream << std::hex << (rand() % 256); //generates each octet for the mac in hex format + if (i<5) { + randStream << ':'; //we need a : between every octet + } + } + // It's ok to strdup, this runs once and will be freed by exiting the process anyway + return strdup(randStream.str().c_str()); //no need for creating a new string, just return this } static int DefaultNumWorkers() {