Fixed memory leak when restore file is disabled and prevent restore file parsing when no write is performed

This commit is contained in:
rexy712 2018-12-16 15:42:22 -08:00
parent 87b7dd2503
commit 2dd52c32b7
2 changed files with 13 additions and 4 deletions

View File

@ -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])){

View File

@ -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);