char *pci_name = NULL;
char *chosen_path = NULL;
char *path = NULL;
- DIR *backlights;
+ DIR *backlights = NULL;
struct dirent *entry;
enum backlight_type type = 0;
char buffer[100];
- struct backlight *backlight;
+ struct backlight *backlight = NULL;
int ret;
if (!drm_device)
if (asprintf(&backlight_path, "%s/%s", "/sys/class/backlight",
entry->d_name) < 0)
- return NULL;
+ goto err;
if (asprintf(&path, "%s/%s", backlight_path, "type") < 0)
- return NULL;
+ goto err;
fd = open(path, O_RDONLY);
free (path);
if (asprintf(&path, "%s/%s", backlight_path, "device") < 0)
- return NULL;
+ goto err;
ret = readlink(path, buffer, sizeof(buffer) - 1);
}
if (!chosen_path)
- return NULL;
+ goto err;
backlight = malloc(sizeof(struct backlight));
if (backlight->brightness < 0)
goto err;
+ closedir(backlights);
return backlight;
err:
- if (chosen_path)
- free(chosen_path);
+ closedir(backlights);
+ free (chosen_path);
free (backlight);
return NULL;
}