[Openmp-commits] [PATCH] D26318: Added check for malloc return

Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 10 01:17:51 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL286441: Added check for malloc return. (authored by achurbanov).

Changed prior to commit:
  https://reviews.llvm.org/D26318?vs=77298&id=77454#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26318

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


Index: openmp/trunk/runtime/src/kmp_i18n.c
===================================================================
--- openmp/trunk/runtime/src/kmp_i18n.c
+++ openmp/trunk/runtime/src/kmp_i18n.c
@@ -827,14 +827,20 @@
             // 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.
             }; // if
             while ( rc == ERANGE ) {   // ERANGE means the buffer is too small.
                 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26318.77454.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20161110/93fcf64b/attachment.bin>


More information about the Openmp-commits mailing list