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
=== removed file 'src/familiar-players-db.vala'
--- src/familiar-players-db.vala 2012-01-10 17:04:50 +0000
+++ src/familiar-players-db.vala 1970-01-01 00:00:00 +0000
@@ -1,164 +0,0 @@
1/*
2Copyright 2010 Canonical Ltd.
3
4Authors:
5 Conor Curran <conor.curran@canonical.com>
6
7This program is free software: you can redistribute it and/or modify it
8under the terms of the GNU General Public License version 3, as published
9by the Free Software Foundation.
10
11This program is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranties of
13MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14PURPOSE. See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License along
17with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20using Gee;
21using GLib.Path;
22using GLib.DirUtils;
23using GLib.FileUtils;
24using GLib.Timeout;
25using GLib.Environment;
26
27// TODO: more refactoring needed here
28public class FamiliarPlayersDB : GLib.Object
29{
30 private const string GROUP_NAME = "Seen Database";
31 private const string KEY_NAME = "DesktopFiles";
32 private const string DEFAULT_APP_DESKTOP = "/usr/share/applications/banshee-1.desktop";
33 private HashMap<string, bool> players_DB;
34 private string file_name;
35 private string dir_name;
36 private KeyFile key_file;
37 private uint write_id;
38
39 public FamiliarPlayersDB()
40 {
41 this.write_id = 0;
42 this.players_DB = new HashMap<string, bool>();
43 if ( !create_key_file() ){
44 this.players_DB.set(DEFAULT_APP_DESKTOP, true);
45 this.write_db();
46 }
47
48 this.dir_name = build_filename(get_user_cache_dir(), "indicator", "sound");
49 this.file_name = build_filename(this.dir_name, "familiar-players-db.keyfile");
50 if(create_key_file() && check_for_keys() && load_data_from_key_file()){
51 debug("keyfiles in place and ready for action");
52 }
53 else{
54 this.key_file = null;
55 warning("FamiliarPlayersDB:: problems loading key file - can't go any further");
56 }
57 }
58
59 private bool create_key_file(){
60 bool result = false;
61 if (test(this.file_name, GLib.FileTest.EXISTS)) {
62 this.key_file = new KeyFile();
63 try{
64 result = this.key_file.load_from_file(this.file_name, KeyFileFlags.NONE);
65 }
66 catch(GLib.KeyFileError e){
67 warning("FamiliarPlayersDB::create_key_file() - KeyFileError");
68 }
69 catch(GLib.FileError e){
70 warning("FamiliarPlayersDB::create_key_file() - FileError");
71 }
72 }
73 return result;
74 }
75
76 private bool check_for_keys(){
77 try{
78 if(this.key_file.has_key(GROUP_NAME, KEY_NAME) == true){
79 return true;
80 }
81 }
82 catch(KeyFileError e){
83 return false;
84 }
85 warning("Seen DB '%s' does not have key '%s' in group '%s'", this.file_name, KEY_NAME, GROUP_NAME);
86 return false;
87 }
88
89 private bool load_data_from_key_file(){
90 try{
91 string[] desktops = this.key_file.get_string_list(GROUP_NAME,
92 KEY_NAME);
93 foreach(string s in desktops){
94 this.players_DB.set(s, true);
95 }
96 return true;
97 }
98 catch(GLib.KeyFileError error){
99 warning("Error loading the Desktop string list");
100 return false;
101 }
102 }
103
104 private bool write_db()
105 {
106 KeyFile keyfile = new KeyFile();
107 string[] desktops = {};
108 foreach(string key in this.players_DB.keys){
109 desktops += key;
110 }
111 keyfile.set_string_list(GROUP_NAME,
112 KEY_NAME,
113 desktops);
114 size_t data_length;
115 string data = null;
116 try{
117 data = keyfile.to_data(out data_length);
118 }
119 catch(GLib.KeyFileError e){
120 warning("Problems dumping keyfile to a string");
121 return false;
122 }
123
124 if(create_with_parents(this.dir_name, 0700) != 0){
125 warning("Unable to make directory: %s", this.dir_name);
126 return false;
127 }
128
129 try{
130 if(set_contents(this.file_name, data, (ssize_t)data_length) == false){
131 warning("Unable to write out file '%s'", this.file_name);
132 }
133 }
134 catch(FileError err){
135 warning("Unable to write out file '%s'", this.file_name);
136 }
137 return true;
138 }
139
140 public void insert(string desktop)
141 {
142 if(already_familiar(desktop) == false){
143 if(this.write_id != 0){
144 Source.remove(this.write_id);
145 this.write_id = 0;
146 }
147 this.write_id = Timeout.add_seconds(60, write_db);
148 this.players_DB.set(desktop.dup(), true);
149 }
150 }
151
152 public bool already_familiar(string desktop)
153 {
154 debug("playerDB->already_familiar - result %s", this.players_DB.keys.contains(desktop).to_string());
155 return this.players_DB.keys.contains(desktop);
156 }
157
158 public Gee.Set<string> records()
159 {
160 return this.players_DB.keys;
161 }
162
163
164}
165\ No newline at end of file0\ No newline at end of file
1661
=== modified file 'src/pulseaudio-mgr.c'
--- src/pulseaudio-mgr.c 2012-03-01 16:00:38 +0000
+++ src/pulseaudio-mgr.c 2012-03-14 19:40:28 +0000
@@ -401,27 +401,39 @@
401 case PA_CONTEXT_READY:401 case PA_CONTEXT_READY:
402 connection_attempts = 0;402 connection_attempts = 0;
403 g_debug("PA_CONTEXT_READY");403 g_debug("PA_CONTEXT_READY");
404
404 if (reconnect_idle_id != 0){405 if (reconnect_idle_id != 0){
405 g_source_remove (reconnect_idle_id);406 g_source_remove (reconnect_idle_id);
406 reconnect_idle_id = 0;407 reconnect_idle_id = 0;
407 }408 }
408 pa_operation *o;
409409
410 pa_context_set_subscribe_callback(c, pm_subscribed_events_callback, userdata);410 pa_context_set_subscribe_callback(c, pm_subscribed_events_callback, userdata);
411411 pa_operation *o = NULL;
412 if (!(o = pa_context_subscribe (c, (pa_subscription_mask_t)412
413 (PA_SUBSCRIPTION_MASK_SINK|413 o = pa_context_subscribe (c, (pa_subscription_mask_t)
414 PA_SUBSCRIPTION_MASK_SOURCE|414 (PA_SUBSCRIPTION_MASK_SINK|
415 PA_SUBSCRIPTION_MASK_SINK_INPUT|415 PA_SUBSCRIPTION_MASK_SOURCE|
416 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|416 PA_SUBSCRIPTION_MASK_SINK_INPUT|
417 PA_SUBSCRIPTION_MASK_SERVER), NULL, NULL))) {417 PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT|
418 g_warning("pa_context_subscribe() failed");418 PA_SUBSCRIPTION_MASK_SERVER),
419 419 NULL,
420 }420 NULL);
421421
422 if (!(o = pa_context_get_server_info (c, pm_server_info_callback, userdata))) {422
423 g_warning("Initial - pa_context_get_server_info() failed");423 if (!o){
424 }424 g_critical("pa_context_subscribe() failed - ?");
425 return;
426 }
427
428 pa_operation_unref(o);
429
430 o = pa_context_get_server_info (c, pm_server_info_callback, userdata);
431
432 if (!o){
433 g_warning("pa_context_get_server_info() failed - ?");
434 return;
435 }
436
425 pa_operation_unref(o);437 pa_operation_unref(o);
426 438
427 break;439 break;

Subscribers

People subscribed via source and target branches