Fixed memory leak when restore file is disabled and prevent restore file parsing when no write is performed
This commit is contained in:
parent
87b7dd2503
commit
2dd52c32b7
@ -155,7 +155,7 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
||||
|
||||
//Check for switches
|
||||
if(CHECK_OPTION(GET, argv[i])){
|
||||
curr->operation |= OP_GET;
|
||||
curr->operation = OP_GET;
|
||||
continue;
|
||||
|
||||
}else if(CHECK_OPTION(FADE, argv[i])){
|
||||
|
||||
@ -264,7 +264,8 @@ void do_list(struct arg_values* args){
|
||||
}
|
||||
|
||||
//Run requested operation on a per device basis
|
||||
void run_device_operations(struct arg_values* a){
|
||||
int run_device_operations(struct arg_values* a){
|
||||
int changes = 0;
|
||||
for(a = a->next;a;a = a->next){
|
||||
switch(a->operation){
|
||||
case OP_LIST:
|
||||
@ -284,10 +285,12 @@ void run_device_operations(struct arg_values* a){
|
||||
case OP_SET:
|
||||
if(prep_offset(a))
|
||||
break;
|
||||
++changes;
|
||||
fade_out(a);
|
||||
break;
|
||||
};
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
//If a global operation is requested, run this to fill arg with all devices, each with the global operation
|
||||
@ -312,6 +315,7 @@ int main(int argc, char** argv){
|
||||
|
||||
struct arg_values args; //A linked list of devices and the requested settings.
|
||||
struct string_array device_names; //List of all led/backlight devices in sysfs.
|
||||
int should_save = 0;
|
||||
|
||||
args = process_cmd_args(argc, argv);
|
||||
if(args.operation == OP_USAGE){
|
||||
@ -360,9 +364,14 @@ int main(int argc, char** argv){
|
||||
if(!args.next){
|
||||
populate_args(&args, &device_names);
|
||||
}
|
||||
run_device_operations(&args);
|
||||
should_save = (run_device_operations(&args) > 0);
|
||||
#ifdef ENABLE_RESTORE_FILE
|
||||
save_restore_file(&device_names, &args); //performs cleanup on args
|
||||
if(should_save)
|
||||
save_restore_file(&device_names, &args); //performs cleanup on args
|
||||
else
|
||||
free_cmd_args(&args);
|
||||
#else
|
||||
free_cmd_args(&args);
|
||||
#endif
|
||||
|
||||
free_string_array(&device_names);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user