This patch fixes error reported by coverity run.
CoverityID: 397140 ("Resource leak"): lfs.c
CoverityID: 397370 ("Resource leak"): dir.c
CoverityID: 397378 ("Resource leak"): obd.c
CoverityID: 397406 ("Resource leak"): obd.c
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I92bbf6749d667631b92868bcaf78af558c250441
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52686
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
const struct fid_array __user *ufa = arg;
struct inode *inode = file_inode(file);
struct ll_sb_info *sbi = ll_i2sbi(inode);
- struct fid_array *lfa = NULL;
- size_t size;
- unsigned int nr;
+ struct fid_array *lfa = NULL, *lfa_new = NULL;
int i, rc, *rcs = NULL;
+ unsigned int nr;
+ bool lfa_flag = false; /* lfa already free'ed */
+ size_t size;
ENTRY;
if (!capable(CAP_DAC_READ_SEARCH) &&
* for which we want to remove FID are visible in the namespace.
*/
if (!fid_is_root(&sbi->ll_root_fid)) {
- struct fid_array *lfa_new = NULL;
int path_len = PATH_MAX, linkno;
struct getinfo_fid2path *gf;
int idx, last_idx = nr - 1;
+ lfa_new = NULL;
+
OBD_ALLOC(lfa_new, size);
if (!lfa_new)
GOTO(free_rcs, rc = -ENOMEM);
gf = kmalloc(sizeof(*gf) + path_len + 1, GFP_NOFS);
if (!gf)
- GOTO(free_rcs, rc = -ENOMEM);
+ GOTO(free_lfa_new, rc = -ENOMEM);
for (idx = 0; idx < nr; idx++) {
linkno = 0;
GFP_NOFS);
if (!tmpgf) {
kfree(gf);
- OBD_FREE(lfa_new, size);
- GOTO(free_rcs, rc = -ENOMEM);
+ GOTO(free_lfa_new, rc = -ENOMEM);
}
gf = tmpgf;
continue;
}
kfree(gf);
OBD_FREE(lfa, size);
+ lfa_flag = true;
lfa = lfa_new;
}
-
if (lfa->fa_nr == 0)
GOTO(free_rcs, rc = rcs[nr - 1]);
rc = -EFAULT;
}
+free_lfa_new:
+ OBD_FREE(lfa_new, size);
free_rcs:
OBD_FREE_PTR_ARRAY(rcs, nr);
free_lfa:
- OBD_FREE(lfa, size);
+ if (!lfa_flag)
+ OBD_FREE(lfa, size);
RETURN(rc);
}
char *mntpath = NULL;
int rc;
- if (argc < 2)
- return CMD_HELP;
+ if (argc < 2) {
+ rc = CMD_HELP;
+ goto out_cmd_help;
+ }
while ((c = getopt_long(argc, argv, "a:D:hl:m:",
long_opts, NULL)) != -1) {
action != HUA_REMOVE) {
fprintf(stderr,
"error: -a is supported only when archiving or removing\n");
- return CMD_HELP;
+ rc = CMD_HELP;
+ goto out_cmd_help;
}
archive_id = atoi(optarg);
break;
progname, argv[optind - 1]);
fallthrough;
case 'h':
- return CMD_HELP;
+ rc = CMD_HELP;
+ goto out_cmd_help;
}
}
/* All remaining args are files, so we have at least nbfile */
nbfile = argc - optind;
- if ((nbfile == 0) && (!filelist))
- return CMD_HELP;
+ if ((nbfile == 0) && (!filelist)) {
+ rc = errno;
+ goto out_errno;
+ }
if (opaque)
opaque_len = strlen(opaque);
if (!hur) {
fprintf(stderr, "Cannot create the request: %s\n",
strerror(errno));
- return errno;
+ rc = errno;
+ goto out_errno;
}
nbfile_alloc = nbfile;
rc = fill_hur_item(hur, i, mntpath, argv[optind + i],
&last_dev);
if (rc)
- goto out_free;
+ goto out_hur;
}
/* from here stop using nb_file, use hur->hur_request.hr_itemcount */
fprintf(stderr, "Cannot read the file list %s: %s\n",
filelist, strerror(errno));
rc = -errno;
- goto out_free;
+ goto out_hur;
}
while ((rc = getline(&line, &len, fp)) != -1) {
hur = oldhur;
rc = -errno;
fclose(fp);
- goto out_free;
+ goto out_hur;
}
size = hur_len(oldhur);
if (size < 0) {
hur = oldhur;
rc = -E2BIG;
fclose(fp);
- goto out_free;
+ goto out_hur;
}
memcpy(hur, oldhur, size);
free(oldhur);
mntpath, line, &last_dev);
if (rc) {
fclose(fp);
- goto out_free;
+ goto out_hur;
}
if (!some_file) {
some_file, strerror(errno));
}
rc = llapi_hsm_request(fullpath, hur);
- if (rc) {
+ if (rc)
fprintf(stderr, "Cannot send HSM request (use of %s): %s\n",
some_file, strerror(-rc));
- goto out_free;
- }
-out_free:
- free(some_file);
+out_hur:
free(hur);
+out_errno:
+ free(some_file);
+out_cmd_help:
return rc;
}
* \retval 1 if ostname is found
* 0 if ostname is not found
* -ENOENT if ostname is deleted
+ * -ENOMEM if Error allocating memory
*/
static int llog_search_ost_cb(const char *record, void *data)
{
char *ostname = data;
char ost_filter[MAX_STRING_SIZE] = {'\0'};
char *add_osc, *del_osc, *setup, *cleanup;
- int rc = 0;
+ int rc = -ENOMEM;
add_osc = get_event_filter(LCFG_LOV_ADD_OBD);
+ if (!add_osc)
+ goto out;
+
del_osc = get_event_filter(LCFG_LOV_DEL_OBD);
+ if (!del_osc)
+ goto out;
+
setup = get_event_filter(LCFG_SETUP);
+ if (!setup)
+ goto out;
+
cleanup = get_event_filter(LCFG_CLEANUP);
- if (!add_osc || !del_osc || !setup || !cleanup) {
- rc = -ENOMEM;
+ if (!cleanup)
goto out;
- }
if (ostname && ostname[0])
snprintf(ost_filter, sizeof(ost_filter), " %s,", ostname);
+ rc = 0;
if (strstr(record, ost_filter)) {
if (strstr(record, add_osc) || strstr(record, setup)) {
rc = 1;
optind++;
}
- if (optind < argc || argc == 1)
+ if (optind < argc || argc == 1) {
+ free(username);
return CMD_HELP;
+ }
data.ioc_dev = cur_device;
data.ioc_u32_1 = id;