[asterisk-commits] mnicholson: branch irroot/t38gateway-trunk r324621 - /team/irroot/t38gateway-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 23 11:05:53 CDT 2011


Author: mnicholson
Date: Thu Jun 23 11:05:50 2011
New Revision: 324621

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=324621
Log:
fix reference counting issues

fax_session_reserve() returns a reference and fax_session_new() returns one as
well.  Also make sure we remove the session from the sessions list if
tech->start_session fails.

Modified:
    team/irroot/t38gateway-trunk/res/res_fax.c

Modified: team/irroot/t38gateway-trunk/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/t38gateway-trunk/res/res_fax.c?view=diff&rev=324621&r1=324620&r2=324621
==============================================================================
--- team/irroot/t38gateway-trunk/res/res_fax.c (original)
+++ team/irroot/t38gateway-trunk/res/res_fax.c Thu Jun 23 11:05:50 2011
@@ -2395,18 +2395,22 @@
  * \return 0 on error 1 on success*/
 static int fax_gateway_start(struct fax_gateway *gateway, struct ast_fax_session_details *details, struct ast_channel *chan)
 {
+	struct ast_fax_session *s;
+
 	/* create the FAX session */
-	if (!(gateway->s = fax_session_new(details, chan, gateway->s, gateway->token))) {
+	if (!(s = fax_session_new(details, chan, gateway->s, gateway->token))) {
 		gateway->token = NULL;
 		ast_log(LOG_ERROR, "Can't create a FAX session, gateway attempt failed.\n");
 		report_fax_status(chan, details, "No Available Resource");
 		return -1;
 	}
+	/* release the reference for the reserved session and replace it with
+	 * the real session */
+	ao2_ref(gateway->s, -1);
+	gateway->s = s;
 	gateway->token = NULL;
 
 	if (gateway->s->tech->start_session(gateway->s) < 0) {
-		ao2_ref(gateway->s, -1);
-		gateway->s = NULL;
 		return -1;
 	}
 
@@ -2663,9 +2667,18 @@
 static void fax_gateway_framehook_destroy(void *data) {
 	struct fax_gateway *gateway = data;
 
-	if (gateway->s && gateway->s->state != AST_FAX_STATE_INACTIVE && gateway->s->state != AST_FAX_STATE_RESERVED) {
-		if (gateway->s->tech->cancel_session) {
-			gateway->s->tech->cancel_session(gateway->s);
+	if (gateway->s) {
+		switch (gateway->s->state) {
+		case AST_FAX_STATE_INITIALIZED:
+		case AST_FAX_STATE_OPEN:
+		case AST_FAX_STATE_ACTIVE:
+		case AST_FAX_STATE_COMPLETE:
+			if (gateway->s->tech->cancel_session) {
+				gateway->s->tech->cancel_session(gateway->s);
+			}
+			/* fall through */
+		default:
+			break;
 		}
 	}
 




More information about the asterisk-commits mailing list