liboffloadmic: Add missed checks for malloc and strdup return values

liboffloadmic/
	* runtime/offload_engine.cpp (Engine::init_process): Use strdup instead
	of sizeof+malloc+sprintf, check for return value.
	* runtime/offload_env.cpp (MicEnvVar::get_env_var_kind): Check for
	strdup return value.
	* runtime/offload_host.cpp (__offload_init_library_once): Check for
	strdup return value.  Fix size calculation of COI_HOST_THREAD_AFFINITY.
	* runtime/emulator/coi_device.cpp (COIProcessWaitForShutdown): Check for
	malloc return value.

From-SVN: r228622
This commit is contained in:
Ilya Verbin 2015-10-08 19:04:43 +00:00 committed by Ilya Verbin
parent bc8642d6ce
commit 6fd2e66a09
5 changed files with 35 additions and 4 deletions

View file

@ -173,8 +173,9 @@ void Engine::init_process(void)
// use putenv instead of setenv as Windows has no setenv.
// Note: putenv requires its argument can't be freed or modified.
// So no free after call to putenv or elsewhere.
char * env_var = (char*) malloc(sizeof("COI_DMA_CHANNEL_COUNT=2"));
sprintf(env_var, "COI_DMA_CHANNEL_COUNT=2");
char * env_var = strdup("COI_DMA_CHANNEL_COUNT=2");
if (env_var == NULL)
LIBOFFLOAD_ERROR(c_malloc);
putenv(env_var);
}
}