Contents of /trunk/hal/patches/hal-0.5.10-fix-file-descriptor-leaks-on-error-conditions.patch
Parent Directory | Revision Log
Revision 597 -
(show annotations)
(download)
Mon May 19 19:05:19 2008 UTC (16 years, 5 months ago) by niro
File size: 2651 byte(s)
Mon May 19 19:05:19 2008 UTC (16 years, 5 months ago) by niro
File size: 2651 byte(s)
-gentoo patches
1 | From 568b5c28c896b6c2420d686a111e7b7bbd5edf5b Mon Sep 17 00:00:00 2001 |
2 | From: Guillem Jover <guillem.jover@nokia.com> |
3 | Date: Tue, 20 Nov 2007 14:47:35 +0100 |
4 | Subject: [PATCH] fix file descriptor leaks on error conditions |
5 | |
6 | Fixed file descriptor leaks on error conditions if open() |
7 | used. |
8 | --- |
9 | hald/create_cache.c | 3 +- |
10 | hald/linux/addons/addon-omap-backlight.c | 36 ++++++++++++++++++----------- |
11 | 2 files changed, 24 insertions(+), 15 deletions(-) |
12 | |
13 | diff --git a/hald/create_cache.c b/hald/create_cache.c |
14 | index 384ed6a..c78c03f 100644 |
15 | --- a/hald/create_cache.c |
16 | +++ b/hald/create_cache.c |
17 | @@ -699,8 +699,9 @@ di_rules_init (void) |
18 | return num_skipped_fdi_files; |
19 | error: |
20 | HAL_ERROR (("Error generating fdi cache")); |
21 | - if (fd < 0) |
22 | + if (fd >= 0) |
23 | close (fd); |
24 | + |
25 | unlink (cachename_temp); |
26 | return -1; |
27 | } |
28 | diff --git a/hald/linux/addons/addon-omap-backlight.c b/hald/linux/addons/addon-omap-backlight.c |
29 | index b05ccbb..d85df79 100644 |
30 | --- a/hald/linux/addons/addon-omap-backlight.c |
31 | +++ b/hald/linux/addons/addon-omap-backlight.c |
32 | @@ -71,13 +71,19 @@ struct backlight bl_data; |
33 | static int |
34 | read_backlight (struct backlight * bl) |
35 | { |
36 | - int fd; |
37 | + int fd, ret; |
38 | |
39 | fd = open ("/sys/devices/platform/omapfb/panel/backlight_level", O_RDONLY); |
40 | - if (fd < 0 || read (fd, buffer, NUM_BUF_LEN) < 0) |
41 | + if (fd < 0) |
42 | return -1; |
43 | |
44 | - return atoi (buffer); |
45 | + ret = read (fd, buffer, NUM_BUF_LEN) |
46 | + close (fd); |
47 | + |
48 | + if (ret >= 0) |
49 | + return atoi (buffer); |
50 | + else |
51 | + return -1; |
52 | } |
53 | |
54 | /* Read maximum bl level */ |
55 | @@ -88,23 +94,25 @@ read_backlight (struct backlight * bl) |
56 | static void |
57 | backlight_init (struct backlight * bl) |
58 | { |
59 | - int fd; |
60 | + int fd, ret; |
61 | |
62 | /* Reading maximum backlight level */ |
63 | fd = open ("/sys/devices/platform/omapfb/panel/backlight_max", O_RDONLY); |
64 | - |
65 | - if (fd < 0 || read (fd, buffer, NUM_BUF_LEN - 1) < 0) |
66 | + if (fd < 0) |
67 | return; |
68 | |
69 | - bl->bl_max = atoi (buffer); |
70 | - close (fd); |
71 | + ret = read(fd, buffer, NUM_BUF_LEN - 1); |
72 | + close(fd); |
73 | + |
74 | + if (ret >= 0) |
75 | + bl->bl_max = atoi (buffer); |
76 | } |
77 | |
78 | /* Setting backlight level */ |
79 | static void |
80 | write_backlight (struct backlight * bl, int level) |
81 | { |
82 | - int fd, l; |
83 | + int fd, l, ret; |
84 | |
85 | /* sanity-checking level we're required to set */ |
86 | if (level > bl->bl_max) |
87 | @@ -114,14 +122,14 @@ write_backlight (struct backlight * bl, int level) |
88 | level = bl->bl_min; |
89 | |
90 | fd = open ("/sys/devices/platform/omapfb/panel/backlight_level", O_WRONLY); |
91 | + if (fd < 0) |
92 | + return; |
93 | + |
94 | l = snprintf (buffer, NUM_BUF_LEN - 1, "%d", level); |
95 | |
96 | - if (l >= (NUM_BUF_LEN - 1)) { |
97 | - close (fd); |
98 | - return; |
99 | - } |
100 | + if (l < (NUM_BUF_LEN - 1)) |
101 | + write (fd, buffer, l); |
102 | |
103 | - write (fd, buffer, l); |
104 | close (fd); |
105 | } |
106 | |
107 | -- |
108 | 1.5.3.7 |
109 |