Summary:ASTERISK-18923: res_fax_spandsp usage counter is wrong
Reporter:Grigoriy Puzankin (boroda)Labels:
Date Opened:2011-11-25 02:46:38.000-0600Date Closed:2014-10-14 11:34:04
Versions: Frequency of
is duplicated byASTERISK-24391 res_fax: fax handler module reference leak
Environment:Attachments:( 0) module_ref.diff
( 1) Screen_Shot_2012-12-17_at_2.17.33_PM_copy.png
Description:When I send fax using SendFAX (from res_fax_spandsp) it increases module usage counter by 2. When fax completes it decreases module usage by 1. So after each iteration counter grows by 1.

Module                         Description                              Use Count
res_fax.so                     Generic FAX Applications                 1        
res_fax_spandsp.so             Spandsp G.711 and T.38 FAX Technologies  11        
2 modules loaded

Current FAX Sessions:

Channel              Tech       FAXID      Type  Operation  State           File(s)                      

0 FAX sessions
Comments:By: ibercom (ibercom) 2012-03-15 14:20:26.061-0500

It is a problem because you can't unload this module. The 'Use Count' always is >0.
I don't use SendFAX, I use ReceiveFAX and its value is incremented by one every time I call to ReceiveFax.

By: John Hass (john8675309tm) 2012-12-17 14:20:47.572-0600

I am also experiencing this issue, the attached pic shows Current Fax sessions that aren't there at all.  What I am afraid of more then anything is switching to the digium res_fax and having all the licenses used up, because the counter is not accurate.

By: Niklas Larsson (pnlarsson) 2013-01-31 06:43:06.333-0600

I have the same issue when using res_fax_spandsp in T38 gateway mode. Below are some info from asterisk:

sipgwdev*CLI> fax show sessions

Current FAX Sessions:

Channel              Tech       FAXID      Type  Operation  State           File(s)                      
SIP/siptrunk01-gw-00 Spandsp    11         none  gateway    Active                                        
SIP/siptrunk01-gw-00 Spandsp    3          none  gateway    Active                                        
SIP/siptrunk03-gw-00 Spandsp    15         none  gateway    Active                                        
SIP/siptrunk03-gw-00 Spandsp    7          none  gateway    Active                                        
SIP/siptrunk01-gw-00 Spandsp    19         none  gateway    Active                                        

5 FAX sessions

sipgwdev*CLI> sip show channels
Peer             User/ANR         Call ID          Format           Hold     Last Message    Expiry     Peer      
0 active SIP dialogs
sipgwdev*CLI> core show channels
Channel              Location             State   Application(Data)            
0 active channels
0 active calls
27 calls processed
sipgwdev*CLI> core show version
Asterisk SVN-branch-10-r379777 built by root @ sipgwdev on a x86_64 running Linux on 2013-01-30 09:29:54 UTC
sipgwdev*CLI> fax show version
FAX For Asterisk Components:
Applications: SVN-branch-10-r379777
Spandsp FAX Driver: 20110122 075024

By: Niklas Larsson (pnlarsson) 2013-02-04 09:55:03.690-0600

I added REF_DEBUG to res_fax.c and res_fax_spandsp.c, sent a fax through (GATEWAY mode) and run refcounter:
Problem: net Refcount not zero for object 28102f78
Object 28102f78 history:
  0x7f5e28102f78 =1   res_fax.c:981:fax_session_new ()
  0x7f5e28102f78 +1   res_fax.c:1052:fax_session_new () [@1]
  0x7f5e28102f78 +1   res_fax_spandsp.c:750:spandsp_fax_gw_gen_alloc () [@2]
  0x7f5e28102f78 +1   res_fax.c:967:fax_session_new () [@3]
  0x7f5e28102f78 +1   res_fax.c:1052:fax_session_new () [@4]
  0x7f5e28102f78 -1   res_fax.c:2582:fax_gateway_start () [@5]
  0x7f5e28102f78 -1   res_fax_spandsp.c:755:spandsp_fax_gw_gen_release () [@4]
  0x7f5e28102f78 +1   res_fax_spandsp.c:750:spandsp_fax_gw_gen_alloc () [@3]
  0x7f5e28102f78 -1   res_fax_spandsp.c:755:spandsp_fax_gw_gen_release () [@4]
  0x7f5e28102f78 -1   res_fax.c:2506:destroy_gateway () [@3]
  0x7f5e28102f78 -1   res_fax.c:2509:destroy_gateway () [@2]

By: Johann Steinwendtner (steinwej) 2013-08-20 07:32:26.427-0500

I 've the same problem on Asterisk 11.5.0. To me it seems that the module counter gets incremented when a new fax session is reserved and also when it is requested. (so IMHO twice)
see function: fax_session_new and fax_session_reserve.
My current workaround is in fax_session_new:
if (!reserved)
But that should be approved.

By: Johann Steinwendtner (steinwej) 2014-01-28 10:06:26.151-0600

patch against 11.7.0

By: Matt Jordan (mjordan) 2014-10-14 12:04:51.819-0500

[~steinwej] - Corey Farrell had a slightly different fix for this that went up on review board - but thanks for your patch. Can you confirm that Corey's fix (which just got committed to the various branches) fixes the issue for you as well?