[Openmp-commits] [openmp] r286441 - Added check for malloc return.

Andrey Churbanov via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 10 01:08:04 PST 2016


Author: achurbanov
Date: Thu Nov 10 03:08:03 2016
New Revision: 286441

URL: http://llvm.org/viewvc/llvm-project?rev=286441&view=rev
Log:
Added check for malloc return.

Patch by Victor Campos.

Differential Revision: https://reviews.llvm.org/D26318

Modified:
    openmp/trunk/runtime/src/kmp_i18n.c

Modified: openmp/trunk/runtime/src/kmp_i18n.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_i18n.c?rev=286441&r1=286440&r2=286441&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_i18n.c (original)
+++ openmp/trunk/runtime/src/kmp_i18n.c Thu Nov 10 03:08:03 2016
@@ -827,6 +827,9 @@ sys_error(
             // TODO: Add checking result of malloc().
             char * buffer = (char *) KMP_INTERNAL_MALLOC( size );
             int    rc;
+            if (buffer == NULL) {
+                KMP_FATAL(MemoryAllocFailed);
+            }
             rc = strerror_r( err, buffer, size );
             if ( rc == -1 ) {
                 rc = errno;            // XSI version sets errno.
@@ -835,6 +838,9 @@ sys_error(
                 KMP_INTERNAL_FREE( buffer );
                 size *= 2;
                 buffer = (char *) KMP_INTERNAL_MALLOC( size );
+                if (buffer == NULL) {
+                    KMP_FATAL(MemoryAllocFailed);
+                }
                 rc = strerror_r( err, buffer, size );
                 if ( rc == -1 ) {
                     rc = errno;        // XSI version sets errno.




More information about the Openmp-commits mailing list