Skip to contentSkip to conversation

: Add check for realloc() failure case

PATCH New Manjeet Pawar 1 participant 1 message May 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Add check for realloc() failure case

From: Manjeet Pawar <[email protected]>
Subject: [PATCH] testcases/network/nfs/nfs_fsstress/fsstress.c: Add check for realloc() failure case

This patch add check for realloc failure case and exit from the testcase if realloc fails.

---
 testcases/network/nfs/nfs_fsstress/fsstress.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
testcases/network/nfs/nfs_fsstress/fsstress.c +6 -2
index ac91262..208c2dc 100644
@@ -330,8 +330,12 @@ int main(int argc, char **argv)
 			process_freq(optarg);
 			break;
 		case 'i':
-			ilist = realloc(ilist, ++ilistlen * sizeof(*ilist));
-			ilist[ilistlen - 1] = strtol(optarg, &p, 16);
+			if(realloc(ilist, ++ilistlen * sizeof(*ilist)) != NULL)
+				ilist[ilistlen - 1] = strtol(optarg, &p, 16);
+			else{
+				fprintf(stderr, "realloc: New memory allocation failed \n");
+				exit(1);
+			}
 			break;
 		case 'l':
 			loops = atoi(optarg);
Signature · 7 lines
1.7.9.5

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list