Index: runtime/src/kmp_environment.c =================================================================== --- runtime/src/kmp_environment.c +++ runtime/src/kmp_environment.c @@ -566,11 +566,10 @@ ) { KMP_INTERNAL_FREE( (void *) block->vars ); - KMP_INTERNAL_FREE( (void *) block->bulk ); + __kmp_str_free(&(block->bulk)); block->count = 0; block->vars = NULL; - block->bulk = NULL; } // __kmp_env_blk_free Index: runtime/src/kmp_i18n.c =================================================================== --- runtime/src/kmp_i18n.c +++ runtime/src/kmp_i18n.c @@ -148,14 +148,19 @@ // Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so // __kmp_i18n_catgets() will not try to open catalog, but will return default message. - __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantOpenMessageCatalog, name ), - KMP_ERR( error ), - KMP_HNT( CheckEnvVar, "NLSPATH", nlspath ), + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantOpenMessageCatalog, name ), + err_code, + KMP_HNT( CheckEnvVar, "NLSPATH", nlspath ), KMP_HNT( CheckEnvVar, "LANG", lang ), - __kmp_msg_null - ); + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } + KMP_INFORM( WillUseDefaultMessages ); KMP_INTERNAL_FREE( nlspath ); KMP_INTERNAL_FREE( lang ); @@ -317,7 +322,7 @@ table->size = 0; KMP_INTERNAL_FREE( (void *) table->sect ); table->sect = NULL; -} // kmp_i8n_table_free +} // kmp_i18n_table_free void @@ -395,30 +400,35 @@ if ( status == KMP_I18N_ABSENT ) { if (__kmp_generate_warnings > kmp_warnings_low) { // AC: only issue warning in case explicitly asked to - DWORD error = GetLastError(); - // Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so - // __kmp_i18n_catgets() will not try to open catalog but will return default message. + DWORD error = GetLastError(); + // Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so + // __kmp_i18n_catgets() will not try to open catalog but will return default message. /* - If message catalog for another architecture found (e.g. OpenMP RTL - for IA-32 architecture opens libompui.dll for Intel(R) 64) - Windows* OS returns error 193 (ERROR_BAD_EXE_FORMAT). However, - FormatMessage fails to return a message for this error, so user - will see: + If message catalog for another architecture found (e.g. OpenMP RTL + for IA-32 architecture opens libompui.dll for Intel(R) 64) + Windows* OS returns error 193 (ERROR_BAD_EXE_FORMAT). However, + FormatMessage fails to return a message for this error, so user + will see: - OMP: Warning #2: Cannot open message catalog "1041\libompui.dll": - OMP: System error #193: (No system error message available) - OMP: Info #3: Default messages will be used. + OMP: Warning #2: Cannot open message catalog "1041\libompui.dll": + OMP: System error #193: (No system error message available) + OMP: Info #3: Default messages will be used. - Issue a hint in this case to let cause of trouble more understandable. + Issue a hint in this case to let cause of trouble more understandable. */ - __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantOpenMessageCatalog, path.str ), - KMP_SYSERRCODE( error ), + __kmp_msg_t err_msg = KMP_SYSERRCODE(error); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantOpenMessageCatalog, path.str ), + err_msg, ( error == ERROR_BAD_EXE_FORMAT ? KMP_HNT( BadExeFormat, path.str, KMP_ARCH_STR ) : __kmp_msg_null ), - __kmp_msg_null - ); - KMP_INFORM( WillUseDefaultMessages ); + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } + + KMP_INFORM( WillUseDefaultMessages ); } } else { // status == KMP_I18N_OPENED @@ -824,7 +834,6 @@ // XSI version of strerror_r. int size = 2048; - // TODO: Add checking result of malloc(). char * buffer = (char *) KMP_INTERNAL_MALLOC( size ); int rc; if (buffer == NULL) { @@ -932,9 +941,9 @@ }; }; // switch fmsg = __kmp_msg_format( format, message.num, message.str ); - KMP_INTERNAL_FREE( (void *) message.str ); + __kmp_str_free(&message.str); __kmp_str_buf_cat( & buffer, fmsg.str, fmsg.len ); - KMP_INTERNAL_FREE( (void *) fmsg.str ); + __kmp_str_free(&fmsg.str); // Format other messages. va_start( args, message ); @@ -958,9 +967,9 @@ }; }; // switch fmsg = __kmp_msg_format( format, message.num, message.str ); - KMP_INTERNAL_FREE( (void *) message.str ); + __kmp_str_free(&message.str); __kmp_str_buf_cat( & buffer, fmsg.str, fmsg.len ); - KMP_INTERNAL_FREE( (void *) fmsg.str ); + __kmp_str_free(&fmsg.str); }; // forever va_end( args ); Index: runtime/src/kmp_itt.c =================================================================== --- runtime/src/kmp_itt.c +++ runtime/src/kmp_itt.c @@ -103,13 +103,21 @@ switch ( err ) { case __itt_error_no_module : { char const * library = va_arg( args, char const * ); - #if KMP_OS_WINDOWS - int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null ); - #else - char const * sys_err = va_arg( args, char const * ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRMESG( sys_err ), __kmp_msg_null ); - #endif +#if KMP_OS_WINDOWS + int sys_err = va_arg( args, int ); + kmp_msg_t err_code = KMP_SYSERRCODE( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), err_code, __kmp_msg_null ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } +#else + char const * sys_err = va_arg( args, char const * ); + kmp_msg_t err_code = KMP_SYSERRMESG( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), err_code, __kmp_msg_null ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } +#endif } break; case __itt_error_no_symbol : { char const * library = va_arg( args, char const * ); @@ -130,12 +138,20 @@ case __itt_error_cant_read_env : { char const * var = va_arg( args, char const * ); int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), KMP_ERR( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_ERR( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), err_code, __kmp_msg_null ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } break; case __itt_error_system : { char const * func = va_arg( args, char const * ); int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_SYSERRCODE( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), err_code, __kmp_msg_null ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } break; default : { KMP_WARNING( IttUnknownError, err ); Index: runtime/src/kmp_settings.c =================================================================== --- runtime/src/kmp_settings.c +++ runtime/src/kmp_settings.c @@ -360,7 +360,7 @@ char const * value, char const * * out ) { - KMP_INTERNAL_FREE( (void *) * out ); + __kmp_str_free(out); * out = __kmp_str_format( "%s", value ); } // __kmp_stg_parse_str #endif @@ -418,12 +418,12 @@ char buffer[256]; char *t; int hasSuffix; - KMP_INTERNAL_FREE( (void *) * out ); + __kmp_str_free(out); t = (char *) strrchr(value, '.'); hasSuffix = t && __kmp_str_eqf( t, suffix ); t = __kmp_str_format( "%s%s", value, hasSuffix ? "" : suffix ); __kmp_expand_file_name( buffer, sizeof(buffer), t); - KMP_INTERNAL_FREE(t); + __kmp_str_free(&t); * out = __kmp_str_format( "%s", buffer ); } // __kmp_stg_parse_file #endif @@ -2235,7 +2235,7 @@ #undef set_respect #undef set_granularity - KMP_INTERNAL_FREE( buffer ); + __kmp_str_free((const char **) &buffer); if ( proclist ) { if ( ! type ) { Index: runtime/src/kmp_str.c =================================================================== --- runtime/src/kmp_str.c +++ runtime/src/kmp_str.c @@ -420,8 +420,7 @@ kmp_str_loc_t * loc ) { __kmp_str_fname_free( & loc->fname ); - KMP_INTERNAL_FREE( loc->_bulk ); - loc->_bulk = NULL; + __kmp_str_free((const char **) &(loc->_bulk)); loc->file = NULL; loc->func = NULL; } // kmp_str_loc_free @@ -478,8 +477,6 @@ So standard malloc() is the only available option. */ -// TODO: Find and replace all regular free() with __kmp_str_free(). - char * __kmp_str_format( // Allocated string. char const * format, // Format string. Index: runtime/src/z_Linux_util.c =================================================================== --- runtime/src/z_Linux_util.c +++ runtime/src/z_Linux_util.c @@ -165,12 +165,16 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( GetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( GetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -193,12 +197,16 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( SetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( SetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -241,12 +249,16 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( GetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( GetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -272,12 +284,16 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( SetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( SetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -710,13 +726,17 @@ rc = sched_setscheduler( 0, sched, & param ); if ( rc != 0 ) { int error = errno; - __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantChangeMonitorPriority ), - KMP_ERR( error ), - KMP_MSG( MonitorWillStarve ), - __kmp_msg_null - ); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantChangeMonitorPriority ), + err_code, + KMP_MSG( MonitorWillStarve ), + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } }; // if } else { // We cannot abort here, because number of CPUs may be enough for all the threads, @@ -959,7 +979,11 @@ #ifdef KMP_THREAD_ATTR status = pthread_attr_destroy( & thread_attr ); if ( status ) { - __kmp_msg(kmp_ms_warning, KMP_MSG( CantDestroyThreadAttrs ), KMP_ERR( status ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_warning, KMP_MSG( CantDestroyThreadAttrs ), err_code, __kmp_msg_null); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } }; // if #endif /* KMP_THREAD_ATTR */ @@ -1055,13 +1079,17 @@ __kmp_monitor_stksize *= 2; goto retry; } + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( - kmp_ms_warning, // should this be fatal? BB - KMP_MSG( CantSetMonitorStackSize, (long int) __kmp_monitor_stksize ), - KMP_ERR( status ), - KMP_HNT( ChangeMonitorStackSize ), - __kmp_msg_null - ); + kmp_ms_warning, // should this be fatal? BB + KMP_MSG( CantSetMonitorStackSize, (long int) __kmp_monitor_stksize ), + err_code, + KMP_HNT( ChangeMonitorStackSize ), + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } }; // if #endif /* _POSIX_THREAD_ATTR_STACKSIZE */ @@ -1117,12 +1145,16 @@ #ifdef KMP_THREAD_ATTR status = pthread_attr_destroy( & thread_attr ); if ( status != 0 ) { - __kmp_msg( // - kmp_ms_warning, - KMP_MSG( CantDestroyThreadAttrs ), - KMP_ERR( status ), - __kmp_msg_null - ); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantDestroyThreadAttrs ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } }; // if #endif Index: runtime/src/z_Windows_NT_util.c =================================================================== --- runtime/src/z_Windows_NT_util.c +++ runtime/src/z_Windows_NT_util.c @@ -560,12 +560,16 @@ if (__kmp_SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL) == 0) { DWORD error = GetLastError(); if (__kmp_affinity_verbose) { // AC: continue silently if not verbose + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantSetThreadAffMask ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( CantSetThreadAffMask ), + err_code, + __kmp_msg_null + ); + if (__kmp_generate_warnings == kmp_warnings_off) { + __kmp_str_free(&err_code.str); + } } } } else {