mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-11 09:18:25 +03:00
fixed dmevent so that it doesn't do a double free when you run
# dmevent -l Also, changed the behaviour of dm_get_registered_device(), so that it doesn't change the pointer you passed in without freeing the memory on a non-next call, and doesn't free your pointer without setting it to NULL on a failed next call.
This commit is contained in:
parent
48a186f172
commit
b355dd7b23
@ -50,8 +50,8 @@ static void print_usage(char *name)
|
||||
}
|
||||
|
||||
/* Parse command line arguments. */
|
||||
static int parse_argv(int argc, char **argv,
|
||||
char **dso_name, char **device, int *reg, int *list)
|
||||
static int parse_argv(int argc, char **argv, char **dso_name_arg,
|
||||
char **device_arg, int *reg, int *list)
|
||||
{
|
||||
int c;
|
||||
const char *options = "d:hlru";
|
||||
@ -59,9 +59,7 @@ static int parse_argv(int argc, char **argv,
|
||||
while ((c = getopt(argc, argv, options)) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
if (!(*dso_name = strdup(optarg)))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
dso_name_arg = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
@ -83,16 +81,13 @@ static int parse_argv(int argc, char **argv,
|
||||
}
|
||||
}
|
||||
|
||||
if (!*dso_name && !(*dso_name = strdup(default_dso_name)))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (optind >= argc) {
|
||||
if (!*list) {
|
||||
fprintf(stderr, "You need to specify a device.\n");
|
||||
return 0;
|
||||
}
|
||||
} else if (!(*device = strdup(argv[optind])))
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
device_arg = argv[optind];
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -100,15 +95,25 @@ static int parse_argv(int argc, char **argv,
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int list = 0, next = 0, ret, reg = default_reg;
|
||||
char *device = NULL, *device_arg, *dso_name = NULL, *dso_name_arg;
|
||||
char *device, *device_arg = NULL, *dso_name, *dso_name_arg = NULL;
|
||||
struct log_data *ldata;
|
||||
|
||||
if (!parse_argv(argc, argv, &dso_name, &device, ®, &list))
|
||||
if (!parse_argv(argc, argv, &dso_name_arg, &device_arg, ®, &list))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
device_arg = device;
|
||||
dso_name_arg = dso_name;
|
||||
if (device_arg){
|
||||
if (!(device = strdup(device_arg)))
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
device = NULL;
|
||||
|
||||
if (dso_name_arg){
|
||||
if (!(dso_name = strdup(dso_name_arg)))
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
if (!(dso_name = strdup(default_dso_name)))
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(!(ldata = malloc(sizeof(*ldata))))
|
||||
exit(ENOMEM);
|
||||
@ -134,12 +139,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
} while (!ret);
|
||||
|
||||
if (dso_name)
|
||||
free(dso_name);
|
||||
|
||||
if (device)
|
||||
free(device);
|
||||
|
||||
ret = (ret && device_arg) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
goto out;
|
||||
}
|
||||
@ -158,11 +157,10 @@ int main(int argc, char **argv)
|
||||
out:
|
||||
multilog_del_type(standard, ldata);
|
||||
|
||||
if (device_arg)
|
||||
free(device_arg);
|
||||
|
||||
if (dso_name_arg)
|
||||
free(dso_name_arg);
|
||||
if (device)
|
||||
free(device);
|
||||
if (dso_name)
|
||||
free(dso_name);
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user