forked from enlightenment/enlightenment
fix filedesc leak in tempget when errs happen - based on info from
maxime, but written differently. SVN revision: 80914
This commit is contained in:
parent
819fa7c948
commit
3dc01f3e7a
|
@ -373,7 +373,7 @@ init(void)
|
||||||
static int
|
static int
|
||||||
check(void)
|
check(void)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int temp = 0;
|
int temp = 0;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
@ -424,13 +424,13 @@ check(void)
|
||||||
char dummy[4096];
|
char dummy[4096];
|
||||||
|
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
|
if (sscanf(buf, "%s %s %i", dummy, dummy, &temp) == 3)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
else
|
else
|
||||||
goto error;
|
goto error;
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -442,8 +442,8 @@ check(void)
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
if (sscanf(buf, "%i", &temp) == 1)
|
if (sscanf(buf, "%i", &temp) == 1)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -461,9 +461,9 @@ check(void)
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
|
||||||
/* actually read the temp */
|
/* actually read the temp */
|
||||||
if (sscanf(buf, "%i", &temp) == 1)
|
if (sscanf(buf, "%i", &temp) == 1)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -471,7 +471,6 @@ check(void)
|
||||||
goto error;
|
goto error;
|
||||||
/* Hack for temp */
|
/* Hack for temp */
|
||||||
temp = temp / 1000;
|
temp = temp / 1000;
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -482,9 +481,9 @@ check(void)
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
|
||||||
/* actually read the temp */
|
/* actually read the temp */
|
||||||
if (sscanf(buf, "%i", &temp) == 1)
|
if (sscanf(buf, "%i", &temp) == 1)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -492,7 +491,6 @@ check(void)
|
||||||
goto error;
|
goto error;
|
||||||
/* Hack for temp */
|
/* Hack for temp */
|
||||||
temp = temp / 1000;
|
temp = temp / 1000;
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -505,9 +503,9 @@ check(void)
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
|
buf[sizeof(buf) - 1] = 0;
|
||||||
p = strchr(buf, ':');
|
p = strchr(buf, ':');
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
|
@ -531,9 +529,9 @@ check(void)
|
||||||
if (f)
|
if (f)
|
||||||
{
|
{
|
||||||
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
if (fgets(buf, sizeof(buf), f) == NULL) goto error;
|
||||||
|
|
||||||
buf[sizeof(buf) - 1] = 0;
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
f = NULL;
|
||||||
|
buf[sizeof(buf) - 1] = 0;
|
||||||
temp = atoi(buf);
|
temp = atoi(buf);
|
||||||
temp /= 1000;
|
temp /= 1000;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -550,6 +548,8 @@ check(void)
|
||||||
|
|
||||||
return -999;
|
return -999;
|
||||||
error:
|
error:
|
||||||
|
if (f) fclose(f);
|
||||||
|
f = NULL;
|
||||||
sensor_type = SENSOR_TYPE_NONE;
|
sensor_type = SENSOR_TYPE_NONE;
|
||||||
if (sensor_name) free(sensor_name);
|
if (sensor_name) free(sensor_name);
|
||||||
sensor_name = NULL;
|
sensor_name = NULL;
|
||||||
|
|
Loading…
Reference in New Issue