Check the error of malloc() function and handle it properly.
Change-Id: I2763d1b6d9c97c137a2593077ee31eaa3758ad81
Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-on: http://review.whamcloud.com/19194
Tested-by: Jenkins
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
/* put an '=' on the end in case it doesn't have one */
if (popt->po_delete && argv[i][len - 1] != '=') {
buf = malloc(len + 1);
/* put an '=' on the end in case it doesn't have one */
if (popt->po_delete && argv[i][len - 1] != '=') {
buf = malloc(len + 1);
+ if (buf == NULL) {
+ rc = -ENOMEM;
+ break;
+ }
sprintf(buf, "%s=", argv[i]);
} else {
buf = argv[i];
sprintf(buf, "%s=", argv[i]);
} else {
buf = argv[i];
/* for delete, make it "<param>=\0" */
buf = malloc(strlen(argv[optind]) + 2);
/* for delete, make it "<param>=\0" */
buf = malloc(strlen(argv[optind]) + 2);
+ if (buf == NULL) {
+ rc = -ENOMEM;
+ goto out;
+ }
/* put an '=' on the end in case it doesn't have one */
sprintf(buf, "%s=", argv[optind]);
/* then truncate after the first '=' */
/* put an '=' on the end in case it doesn't have one */
sprintf(buf, "%s=", argv[optind]);
/* then truncate after the first '=' */
rc = -ENOMEM;
} else {
rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
rc = -ENOMEM;
} else {
rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
+ if (rc < 0)
+ rc = -errno;
- if (buf)
- free(buf);
- if (rc < 0) {
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
- }
+ if (buf)
+ free(buf);
+out:
+ if (rc < 0) {
+ fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
+ strerror(-rc));
+ }