Annotation of /trunk/hal/patches/hal-0.5.10-libhal-fix-memory-leaks-after-out-of-memory-conditi.patch
Parent Directory | Revision Log
Revision 597 -
(hide annotations)
(download)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 2554 byte(s)
Mon May 19 19:05:19 2008 UTC (16 years, 4 months ago) by niro
File size: 2554 byte(s)
-gentoo patches
1 | niro | 597 | From 726dbf7155135e607f38e0c93dc1441b800694c4 Mon Sep 17 00:00:00 2001 |
2 | From: Guillem Jover <guillem.jover@nokia.com> | ||
3 | Date: Wed, 28 Nov 2007 16:43:37 +0100 | ||
4 | Subject: [PATCH] libhal: fix memory leaks after out of memory conditions | ||
5 | |||
6 | Fixed memory leaks after out of memory conditions. | ||
7 | --- | ||
8 | libhal/libhal.c | 25 +++++++++++++++++++------ | ||
9 | 1 files changed, 19 insertions(+), 6 deletions(-) | ||
10 | |||
11 | diff --git a/libhal/libhal.c b/libhal/libhal.c | ||
12 | index 2697239..1e66bf4 100644 | ||
13 | --- a/libhal/libhal.c | ||
14 | +++ b/libhal/libhal.c | ||
15 | @@ -116,6 +116,7 @@ libhal_get_string_array_from_iter (DBusMessageIter *iter, int *num_elements) | ||
16 | { | ||
17 | int count; | ||
18 | char **buffer; | ||
19 | + char **t; | ||
20 | |||
21 | count = 0; | ||
22 | buffer = (char **)malloc (sizeof (char *) * 8); | ||
23 | @@ -129,9 +130,11 @@ libhal_get_string_array_from_iter (DBusMessageIter *iter, int *num_elements) | ||
24 | char *str; | ||
25 | |||
26 | if ((count % 8) == 0 && count != 0) { | ||
27 | - buffer = realloc (buffer, sizeof (char *) * (count + 8)); | ||
28 | - if (buffer == NULL) | ||
29 | + t = realloc (buffer, sizeof (char *) * (count + 8)); | ||
30 | + if (t == NULL) | ||
31 | goto oom; | ||
32 | + else | ||
33 | + buffer = t; | ||
34 | } | ||
35 | |||
36 | dbus_message_iter_get_basic (iter, &value); | ||
37 | @@ -146,9 +149,11 @@ libhal_get_string_array_from_iter (DBusMessageIter *iter, int *num_elements) | ||
38 | } | ||
39 | |||
40 | if ((count % 8) == 0) { | ||
41 | - buffer = realloc (buffer, sizeof (char *) * (count + 1)); | ||
42 | - if (buffer == NULL) | ||
43 | + t = realloc (buffer, sizeof (char *) * (count + 1)); | ||
44 | + if (t == NULL) | ||
45 | goto oom; | ||
46 | + else | ||
47 | + buffer = t; | ||
48 | } | ||
49 | |||
50 | buffer[count] = NULL; | ||
51 | @@ -157,6 +162,8 @@ libhal_get_string_array_from_iter (DBusMessageIter *iter, int *num_elements) | ||
52 | return buffer; | ||
53 | |||
54 | oom: | ||
55 | + if (buffer != NULL) | ||
56 | + free (buffer); | ||
57 | fprintf (stderr, "%s %d : error allocating memory\n", __FILE__, __LINE__); | ||
58 | return NULL; | ||
59 | |||
60 | @@ -414,6 +421,7 @@ get_property_set (DBusMessageIter *iter) | ||
61 | dbus_message_iter_get_element_type (iter) != DBUS_TYPE_DICT_ENTRY) { | ||
62 | fprintf (stderr, "%s %d : error, expecting an array of dict entries\n", | ||
63 | __FILE__, __LINE__); | ||
64 | + free (result); | ||
65 | return NULL; | ||
66 | } | ||
67 | |||
68 | @@ -436,8 +444,10 @@ get_property_set (DBusMessageIter *iter) | ||
69 | goto oom; | ||
70 | |||
71 | p->key = strdup (key); | ||
72 | - if (p->key == NULL) | ||
73 | + if (p->key == NULL) { | ||
74 | + free (p); | ||
75 | goto oom; | ||
76 | + } | ||
77 | |||
78 | dbus_message_iter_next (&dict_entry_iter); | ||
79 | |||
80 | @@ -456,10 +466,13 @@ get_property_set (DBusMessageIter *iter) | ||
81 | return result; | ||
82 | |||
83 | oom: | ||
84 | + if (result != NULL) | ||
85 | + libhal_free_property_set (result); | ||
86 | + | ||
87 | fprintf (stderr, | ||
88 | "%s %d : error allocating memory\n", | ||
89 | __FILE__, __LINE__); | ||
90 | - /** @todo FIXME cleanup */ | ||
91 | + | ||
92 | return NULL; | ||
93 | } | ||
94 | |||
95 | -- | ||
96 | 1.5.3.7 | ||
97 |