Merge lp:~cjcurran/indicator-sound/coverity-fixes into lp:indicator-sound/fifth

Proposed by Conor Curran
Status: Merged
Approved by: Charles Kerr
Approved revision: 308
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~cjcurran/indicator-sound/coverity-fixes
Merge into: lp:indicator-sound/fifth
Diff against target: 228 lines (+27/-179)
2 files modified
src/familiar-players-db.vala (+0/-164)
src/pulseaudio-mgr.c (+27/-15)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/coverity-fixes
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+97500@code.launchpad.net

Description of the change

fixes a few little things

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

the fix looks good.

Actually, though, I don't think Coverity was giving a false positive here... looks like the first "o" was leaking?

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

merged in r307

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'src/familiar-players-db.vala'
2--- src/familiar-players-db.vala 2012-01-10 17:04:50 +0000
3+++ src/familiar-players-db.vala 1970-01-01 00:00:00 +0000
4@@ -1,164 +0,0 @@
5-/*
6-Copyright 2010 Canonical Ltd.
7-
8-Authors:
9- Conor Curran <conor.curran@canonical.com>
10-
11-This program is free software: you can redistribute it and/or modify it
12-under the terms of the GNU General Public License version 3, as published
13-by the Free Software Foundation.
14-
15-This program is distributed in the hope that it will be useful, but
16-WITHOUT ANY WARRANTY; without even the implied warranties of
17-MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18-PURPOSE. See the GNU General Public License for more details.
19-
20-You should have received a copy of the GNU General Public License along
21-with this program. If not, see <http://www.gnu.org/licenses/>.
22-*/
23-
24-using Gee;
25-using GLib.Path;
26-using GLib.DirUtils;
27-using GLib.FileUtils;
28-using GLib.Timeout;
29-using GLib.Environment;
30-
31-// TODO: more refactoring needed here
32-public class FamiliarPlayersDB : GLib.Object
33-{
34- private const string GROUP_NAME = "Seen Database";
35- private const string KEY_NAME = "DesktopFiles";
36- private const string DEFAULT_APP_DESKTOP = "/usr/share/applications/banshee-1.desktop";
37- private HashMap<string, bool> players_DB;
38- private string file_name;
39- private string dir_name;
40- private KeyFile key_file;
41- private uint write_id;
42-
43- public FamiliarPlayersDB()
44- {
45- this.write_id = 0;
46- this.players_DB = new HashMap<string, bool>();
47- if ( !create_key_file() ){
48- this.players_DB.set(DEFAULT_APP_DESKTOP, true);
49- this.write_db();
50- }
51-
52- this.dir_name = build_filename(get_user_cache_dir(), "indicator", "sound");
53- this.file_name = build_filename(this.dir_name, "familiar-players-db.keyfile");
54- if(create_key_file() && check_for_keys() && load_data_from_key_file()){
55- debug("keyfiles in place and ready for action");
56- }
57- else{
58- this.key_file = null;
59- warning("FamiliarPlayersDB:: problems loading key file - can't go any further");
60- }
61- }
62-
63- private bool create_key_file(){
64- bool result = false;
65- if (test(this.file_name, GLib.FileTest.EXISTS)) {
66- this.key_file = new KeyFile();
67- try{
68- result = this.key_file.load_from_file(this.file_name, KeyFileFlags.NONE);
69- }
70- catch(GLib.KeyFileError e){
71- warning("FamiliarPlayersDB::create_key_file() - KeyFileError");
72- }
73- catch(GLib.FileError e){
74- warning("FamiliarPlayersDB::create_key_file() - FileError");
75- }
76- }
77- return result;
78- }
79-
80- private bool check_for_keys(){
81- try{
82- if(this.key_file.has_key(GROUP_NAME, KEY_NAME) == true){
83- return true;
84- }
85- }
86- catch(KeyFileError e){
87- return false;
88- }
89- warning("Seen DB '%s' does not have key '%s' in group '%s'", this.file_name, KEY_NAME, GROUP_NAME);
90- return false;
91- }
92-
93- private bool load_data_from_key_file(){
94- try{
95- string[] desktops = this.key_file.get_string_list(GROUP_NAME,
96- KEY_NAME);
97- foreach(string s in desktops){
98- this.players_DB.set(s, true);
99- }
100- return true;
101- }
102- catch(GLib.KeyFileError error){
103- warning("Error loading the Desktop string list");
104- return false;
105- }
106- }
107-
108- private bool write_db()
109- {
110- KeyFile keyfile = new KeyFile();
111- string[] desktops = {};
112- foreach(string key in this.players_DB.keys){
113- desktops += key;
114- }
115- keyfile.set_string_list(GROUP_NAME,
116- KEY_NAME,
117- desktops);
118- size_t data_length;
119- string data = null;
120- try{
121- data = keyfile.to_data(out data_length);
122- }
123- catch(GLib.KeyFileError e){
124- warning("Problems dumping keyfile to a string");
125- return false;
126- }
127-
128- if(create_with_parents(this.dir_name, 0700) != 0){
129- warning("Unable to make directory: %s", this.dir_name);
130- return false;
131- }
132-
133- try{
134- if(set_contents(this.file_name, data, (ssize_t)data_length) == false){
135- warning("Unable to write out file '%s'", this.file_name);
136- }
137- }
138- catch(FileError err){
139- warning("Unable to write out file '%s'", this.file_name);
140- }
141- return true;
142- }
143-
144- public void insert(string desktop)
145- {
146- if(already_familiar(desktop) == false){
147- if(this.write_id != 0){
148- Source.remove(this.write_id);
149- this.write_id = 0;
150- }
151- this.write_id = Timeout.add_seconds(60, write_db);
152- this.players_DB.set(desktop.dup(), true);
153- }
154- }
155-
156- public bool already_familiar(string desktop)
157- {
158- debug("playerDB->already_familiar - result %s", this.players_DB.keys.contains(desktop).to_string());
159- return this.players_DB.keys.contains(desktop);
160- }
161-
162- public Gee.Set<string> records()
163- {
164- return this.players_DB.keys;
165- }
166-
167-
168-}
169\ No newline at end of file
170
171=== modified file 'src/pulseaudio-mgr.c'
172--- src/pulseaudio-mgr.c 2012-03-01 16:00:38 +0000
173+++ src/pulseaudio-mgr.c 2012-03-14 19:40:28 +0000
174@@ -401,27 +401,39 @@
175 case PA_CONTEXT_READY:
176 connection_attempts = 0;
177 g_debug("PA_CONTEXT_READY");
178+
179 if (reconnect_idle_id != 0){
180 g_source_remove (reconnect_idle_id);
181 reconnect_idle_id = 0;
182 }
183- pa_operation *o;
184
185 pa_context_set_subscribe_callback(c, pm_subscribed_events_callback, userdata);
186-
187- if (!(o = pa_context_subscribe (c, (pa_subscription_mask_t)
188- (PA_SUBSCRIPTION_MASK_SINK|
189- PA_SUBSCRIPTION_MASK_SOURCE|
190- PA_SUBSCRIPTION_MASK_SINK_INPUT|
191- PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
192- PA_SUBSCRIPTION_MASK_SERVER), NULL, NULL))) {
193- g_warning("pa_context_subscribe() failed");
194-
195- }
196-
197- if (!(o = pa_context_get_server_info (c, pm_server_info_callback, userdata))) {
198- g_warning("Initial - pa_context_get_server_info() failed");
199- }
200+ pa_operation *o = NULL;
201+
202+ o = pa_context_subscribe (c, (pa_subscription_mask_t)
203+ (PA_SUBSCRIPTION_MASK_SINK|
204+ PA_SUBSCRIPTION_MASK_SOURCE|
205+ PA_SUBSCRIPTION_MASK_SINK_INPUT|
206+ PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
207+ PA_SUBSCRIPTION_MASK_SERVER),
208+ NULL,
209+ NULL);
210+
211+
212+ if (!o){
213+ g_critical("pa_context_subscribe() failed - ?");
214+ return;
215+ }
216+
217+ pa_operation_unref(o);
218+
219+ o = pa_context_get_server_info (c, pm_server_info_callback, userdata);
220+
221+ if (!o){
222+ g_warning("pa_context_get_server_info() failed - ?");
223+ return;
224+ }
225+
226 pa_operation_unref(o);
227
228 break;

Subscribers

People subscribed via source and target branches