Call find_param_fini() on error so that the params are not leaked
during initialization if there is an intermediate error.
Zero out the parameters as they are freed, so if find_param_fini()
is called multiple times (as it is in some error paths) it does
not corrupt the heap by double freeing pointers. This can be hit
by calling "lfs getstripe -m" on multiple pathnames, some of which
do not exist.
Test-Parameters: trivial
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Ie0d7e9ee134deb0633af2f8052b8a458333ebbe5
Reviewed-on: https://review.whamcloud.com/34711
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
}
run_test 27g "$LFS getstripe with no objects"
}
run_test 27g "$LFS getstripe with no objects"
+test_27ga() {
+ test_mkdir $DIR/$tdir
+ touch $DIR/$tdir/$tfile || error "touch failed"
+ ln -s bogus $DIR/$tdir/$tfile.2 || error "ln failed"
+ $LFS getstripe -m $DIR/$tdir/$tfile $DIR/$tdir/$tfile.2
+ local rc=$?
+ (( rc == 2 )) || error "getstripe did not return ENOENT"
+}
+run_test 27ga "$LFS getstripe with missing file (should return error)"
+
test_27i() {
test_mkdir $DIR/$tdir
touch $DIR/$tdir/$tfile || error "touch failed"
test_27i() {
test_mkdir $DIR/$tdir
touch $DIR/$tdir/$tfile || error "touch failed"
#define OBD_NOT_FOUND (-1)
#define OBD_NOT_FOUND (-1)
+static void find_param_fini(struct find_param *param)
+{
+ if (param->fp_migrate)
+ return;
+
+ if (param->fp_obd_indexes) {
+ free(param->fp_obd_indexes);
+ param->fp_obd_indexes = NULL;
+ }
+
+ if (param->fp_lmd) {
+ free(param->fp_lmd);
+ param->fp_lmd = NULL;
+ }
+
+ if (param->fp_lmv_md) {
+ free(param->fp_lmv_md);
+ param->fp_lmv_md = NULL;
+ }
+}
+
static int common_param_init(struct find_param *param, char *path)
{
int lum_size = get_mds_md_size(path);
static int common_param_init(struct find_param *param, char *path)
{
int lum_size = get_mds_md_size(path);
"error: allocation of %d bytes for ioctl",
lmv_user_md_size(param->fp_lmv_stripe_count,
LMV_USER_MAGIC_SPECIFIC));
"error: allocation of %d bytes for ioctl",
lmv_user_md_size(param->fp_lmv_stripe_count,
LMV_USER_MAGIC_SPECIFIC));
+ find_param_fini(param);
-static void find_param_fini(struct find_param *param)
-{
- if (param->fp_migrate)
- return;
-
- if (param->fp_obd_indexes)
- free(param->fp_obd_indexes);
-
- if (param->fp_lmd)
- free(param->fp_lmd);
-
- if (param->fp_lmv_md)
- free(param->fp_lmv_md);
-}
-
static int cb_common_fini(char *path, DIR *parent, DIR **dirp, void *data,
struct dirent64 *de)
{
static int cb_common_fini(char *path, DIR *parent, DIR **dirp, void *data,
struct dirent64 *de)
{
fd = open(dname, O_RDONLY | O_NONBLOCK);
if (fd == -1) {
rc = -errno;
fd = open(dname, O_RDONLY | O_NONBLOCK);
if (fd == -1) {
rc = -errno;
- free(dname);
- return rc;
}
strcpy((char *)lum, fname);
}
strcpy((char *)lum, fname);
if (close(fd) == -1 && rc == 0)
rc = -errno;
if (close(fd) == -1 && rc == 0)
rc = -errno;
free(dname);
return rc;
}
free(dname);
return rc;
}
free(forged_v1);
return ret;
}
free(forged_v1);
return ret;
}