Fixed memory leak

This commit is contained in:
rexy712 2018-01-13 07:29:50 -08:00
parent 5f2684cd93
commit 016ac44bb1

View File

@ -189,7 +189,7 @@ int main(int argc, char** argv){
} }
//save our starting directory so we can change to each backlight directory (makes logic easier) //save our starting directory so we can change to each backlight directory (makes logic easier)
const char* starting_dir = getcwd(NULL, 0); char* starting_dir = getcwd(NULL, 0);
if(chdir(backlight_dir)){ if(chdir(backlight_dir)){
fprintf(stderr, "Unable to read backlight sysfs directory!\n"); fprintf(stderr, "Unable to read backlight sysfs directory!\n");
@ -215,11 +215,15 @@ int main(int argc, char** argv){
fclose(bright); fclose(bright);
} }
free_string_array(&backlight_names); free_string_array(&backlight_names);
//Return to start directory
if(chdir(starting_dir)){ if(chdir(starting_dir)){
free(starting_dir);
fprintf(stderr, "Could not return to starting directory!\nWas the directory moved/deleted?\n"); fprintf(stderr, "Could not return to starting directory!\nWas the directory moved/deleted?\n");
if(chdir(getenv("HOME")) || chdir("/")){ if(chdir(getenv("HOME")) || chdir("/")){
return -5; return -5;
} }
} }
free(starting_dir);
return 0; return 0;
} }