The use of g_idle_add can cause a segmentation fault if the object is
destroyed in the meantime.
---
 drivers/hfpmodem/call-volume.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/hfpmodem/call-volume.c b/drivers/hfpmodem/call-volume.c
index 504b0a5..0d7431e 100644
--- a/drivers/hfpmodem/call-volume.c
+++ b/drivers/hfpmodem/call-volume.c
@@ -50,6 +50,7 @@ struct cv_data {
        GAtChat *chat;
        unsigned char sp_volume;
        unsigned char mic_volume;
+       guint register_source;
 };
 
 static void cv_generic_set_cb(gboolean ok, GAtResult *result,
@@ -173,6 +174,8 @@ static gboolean hfp_call_volume_register(gpointer user_data)
 
        DBG("");
 
+       vd->register_source = 0;
+
        g_at_chat_register(vd->chat, "+VGS:", vgs_notify, FALSE, cv, NULL);
        g_at_chat_register(vd->chat, "+VGM:", vgm_notify, FALSE, cv, NULL);
 
@@ -197,7 +200,7 @@ static int hfp_call_volume_probe(struct ofono_call_volume 
*cv,
 
        ofono_call_volume_set_data(cv, vd);
 
-       g_idle_add(hfp_call_volume_register, cv);
+       vd->register_source = g_idle_add(hfp_call_volume_register, cv);
 
        return 0;
 }
@@ -206,6 +209,9 @@ static void hfp_call_volume_remove(struct ofono_call_volume 
*cv)
 {
        struct cv_data *vd = ofono_call_volume_get_data(cv);
 
+       if (vd->register_source != 0)
+               g_source_remove(vd->register_source);
+
        ofono_call_volume_set_data(cv, NULL);
 
        g_at_chat_unref(vd->chat);
-- 
1.7.6.4

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to