Source

asterisk-voicechanger / app_voicechanger.c

Diff from to

File app_voicechanger.c

 	struct voicechanger *vc;
 	if (data) {
 		vc = (struct voicechanger *)data;
-		if (vc->ah) {
-			ast_free(vc->ah);
-		}
-		vc_soundtouch_free(vc->st8k);
-		vc_soundtouch_free(vc->st16k);
-		ast_free(vc);
-		ast_log(LOG_DEBUG, "freed voice changer resources\n");
+		vc_soundtouch_free(vc->st8k); vc->st8k = NULL;
+		vc_soundtouch_free(vc->st16k); vc->st16k = NULL;
+		ast_audiohook_detach(vc->ah);
+		ast_audiohook_destroy(vc->ah);
+		ast_free(data);
 	}
+	ast_log(LOG_DEBUG, "freed voice changer resources\n");
 }
 
 static int install_vc(struct ast_channel *chan, float pitch)
 	struct ast_datastore *ds;
 	struct voicechanger *vc;
 
+	ast_log(LOG_DEBUG, "pitch is %f\n", pitch);
 	if (-0.1 < pitch && pitch < 0.1) {
 		return 0;
 	}
 static int uninstall_vc(struct ast_channel *chan)
 {
 	struct ast_datastore *ds;
-	struct voicechanger *vc;
 	ast_log(LOG_DEBUG, "Detaching Voice Changer from channel...\n");
 	ast_channel_lock(chan);
 	ds = ast_channel_datastore_find(chan, dsinfo, app);
+	if (ds) {
+		ast_channel_datastore_remove(chan, ds);
+		ast_datastore_free(ds);
+	}
 	ast_channel_unlock(chan);
-	if (ds) {
-		vc = (struct voicechanger *)ds->data;
-		if (ast_audiohook_detach_source(chan, app) != 0) {
-			ast_log(LOG_WARNING, "could not find audiohook :(\n");
-		}
-	} else {
-		ast_log(LOG_NOTICE, "voicechanger doesn't seem attached\n");
-	}
 	return 0;
 }