Bug 712226 - Crash when fclose(NULL)'ing a battery-status FILE*, r=mwu

This commit is contained in:
Chris Jones 2011-12-21 17:58:29 -08:00
Родитель 1304408f8f
Коммит 578b5b5e49
1 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -289,15 +289,17 @@ GetCurrentBatteryInformation(hal::BatteryInformation *aBatteryInfo)
{
FILE *capacityFile = fopen("/sys/class/power_supply/battery/capacity", "r");
double capacity = dom::battery::kDefaultLevel * 100;
if (capacityFile)
if (capacityFile) {
fscanf(capacityFile, "%lf", &capacity);
fclose(capacityFile);
fclose(capacityFile);
}
FILE *chargingFile = fopen("/sys/class/power_supply/battery/charging_source", "r");
int chargingSrc = 1;
if (chargingFile)
if (chargingFile) {
fscanf(chargingFile, "%d", &chargingSrc);
fclose(chargingFile);
fclose(chargingFile);
}
aBatteryInfo->level() = capacity / 100;
aBatteryInfo->charging() = chargingSrc == 1;