Private
Public Access
2
0

jsonplatform.c: properly reallocate memory for platform name

Fixes #761.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Alex Tereschenko
2017-07-01 17:49:09 +02:00
committed by Brendan Le Foll
parent bd3d9d8cab
commit caf75a68c0

View File

@@ -709,7 +709,16 @@ mraa_init_json_platform(const char* platform_json)
free(plat);
// Set the new one in it's place
plat = board;
platform_name = plat->platform_name;
// This one was allocated and assigned an "Unknown platform" value by now,
// so we need to reallocate it.
free(platform_name);
platform_name = calloc(strlen(plat->platform_name) + 1, sizeof(char));
if (platform_name == NULL) {
syslog(LOG_ERR, "init_json_platform: Could not allocate memory for platform_name");
goto unsuccessful;
}
strncpy(platform_name, plat->platform_name, strlen(plat->platform_name) + 1);
// We made it to the end without anything going wrong, just cleanup
ret = MRAA_SUCCESS;