+2015-10-08 Ilya Verbin <ilya.verbin@intel.com>
+
+ * 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.
+
2015-09-29 Ilya Verbin <ilya.verbin@intel.com>
* plugin/libgomp-plugin-intelmic.cpp (OFFLOAD_ACTIVE_WAIT_ENV): New
case CMD_PIPELINE_CREATE:
{
/* Receive data from host. */
- uint32_t *pipeline_num = (uint32_t *) malloc (sizeof (uint32_t));
+ uint32_t *pipeline_num;
+ MALLOC (uint32_t *, pipeline_num, sizeof (uint32_t));
READ (pipe_host2tgt, pipeline_num, sizeof (*pipeline_num));
/* Create a new thread for the pipeline. */
// 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);
}
}
*env_var_name_length = 3;
*env_var_name = *env_var_def = c;
*env_var_def = strdup(*env_var_def);
+ if (*env_var_def == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
return c_mic_var;
}
*env_var_def = c + strlen("ENV=");
*env_var_def = strdup(*env_var_def);
+ if (*env_var_def == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
return c_mic_card_env;
}
if (isalpha(*c)) {
return c_no_mic;
}
*env_var_def = strdup(*env_var_def);
+ if (*env_var_def == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
return card_is_set? c_mic_card_var : c_mic_var;
}
if (strcasecmp(env_var, "none") != 0) {
// value is composed of comma separated physical device indexes
char *buf = strdup(env_var);
+ if (buf == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
char *str, *ptr;
for (str = strtok_r(buf, ",", &ptr); str != 0;
str = strtok_r(0, ",", &ptr)) {
if (env_var != 0) {
char * new_env_var =
(char*) malloc(sizeof("COI_HOST_THREAD_AFFINITY=") +
- sizeof(env_var) + 1);
+ strlen(env_var));
+ if (new_env_var == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
sprintf(new_env_var, "COI_HOST_THREAD_AFFINITY=%s", env_var);
putenv(new_env_var);
}
env_var = getenv("MIC_LD_LIBRARY_PATH");
if (env_var != 0) {
mic_library_path = strdup(env_var);
+ if (mic_library_path == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
}
const char *base_name = "offload_main";
if (mic_library_path != 0) {
char *buf = strdup(mic_library_path);
+ if (buf == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
char *try_name = (char*) alloca(strlen(mic_library_path) +
strlen(base_name) + 2);
char *dir, *ptr;
struct stat st;
if (stat(try_name, &st) == 0 && S_ISREG(st.st_mode)) {
mic_device_main = strdup(try_name);
+ if (mic_device_main == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
break;
}
}
env_var = getenv("MIC_PROXY_FS_ROOT");
if (env_var != 0 && *env_var != '\0') {
mic_proxy_fs_root = strdup(env_var);
+ if (mic_proxy_fs_root == NULL)
+ LIBOFFLOAD_ERROR(c_malloc);
}
// Prepare environment for the target process using the following