[Openmp-commits] [PATCH] D26318: Added check for malloc return
Victor Campos via Openmp-commits
openmp-commits at lists.llvm.org
Tue Nov 8 17:45:09 PST 2016
vhscampos updated this revision to Diff 77298.
https://reviews.llvm.org/D26318
Files:
runtime/src/kmp_i18n.c
Index: runtime/src/kmp_i18n.c
===================================================================
--- runtime/src/kmp_i18n.c
+++ runtime/src/kmp_i18n.c
@@ -826,22 +826,28 @@
int size = 2048;
// TODO: Add checking result of malloc().
char * buffer = (char *) KMP_INTERNAL_MALLOC( size );
+ if (buffer == NULL) {
+ KMP_FATAL(MemoryAllocFailed);
+ }
int rc;
rc = strerror_r( err, buffer, size );
if ( rc == -1 ) {
- rc = errno; // XSI version sets errno.
+ 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 );
- rc = strerror_r( err, buffer, size );
- if ( rc == -1 ) {
- rc = errno; // XSI version sets errno.
- }; // if
+ 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.
+ }; // if
}; // while
if ( rc == 0 ) {
- message = buffer;
+ message = buffer;
} else {
// Buffer is unused. Free it.
KMP_INTERNAL_FREE( buffer );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26318.77298.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20161109/9c519138/attachment.bin>
More information about the Openmp-commits
mailing list