Changeset 5438:4eb05969f66c in roaraudio for libroar/roardl.c


Ignore:
Timestamp:
03/20/12 17:00:08 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

fix code so refcount is correct and avoid double free

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/roardl.c

    r5431 r5438  
    110110int roar_dl_para_ref                    (struct roar_dl_librarypara * para) { 
    111111 if ( para == NULL ) { 
     112  ROAR_DBG("roar_dl_para_ref(para=%p) = -1 // error=FAULT", para); 
    112113  roar_err_set(ROAR_ERROR_FAULT); 
    113114  return -1; 
     
    116117 para->refc++; 
    117118 
     119 ROAR_DBG("roar_dl_para_ref(para=%p) = 0", para); 
    118120 return 0; 
    119121} 
     
    121123int roar_dl_para_unref                  (struct roar_dl_librarypara * para) { 
    122124 if ( para == NULL ) { 
     125  ROAR_DBG("roar_dl_para_unref(para=%p) = -1 // error=FAULT", para); 
    123126  roar_err_set(ROAR_ERROR_FAULT); 
    124127  return -1; 
     
    127130 para->refc--; 
    128131 
    129  if ( para->refc ) 
     132 if ( para->refc ) { 
     133  ROAR_DBG("roar_dl_para_unref(para=%p) = 0", para); 
    130134  return 0; 
     135 } 
    131136 
    132137 if ( para->notifycore != NULL ) 
     
    140145 roar_mm_free(para); 
    141146 
     147 ROAR_DBG("roar_dl_para_unref(para=%p) = 0", para); 
    142148 return 0; 
    143149} 
     
    408414int                      roar_dl_ref    (struct roar_dl_lhandle * lhandle) { 
    409415 if ( (void*)lhandle < (void*)128 ) { 
     416  ROAR_DBG("roar_dl_ref(lhandle=%p) = -1 // error=BADFH", lhandle); 
    410417  roar_err_set(ROAR_ERROR_BADFH); 
    411418  return -1; 
     
    414421 lhandle->refc++; 
    415422 
     423 ROAR_DBG("roar_dl_ref(lhandle=%p) = 0", lhandle); 
    416424 return 0; 
    417425} 
     
    421429 
    422430 if ( (void*)lhandle < (void*)128 ) { 
     431  ROAR_DBG("roar_dl_unref(lhandle=%p) = -1 // error=BADFH", lhandle); 
    423432  roar_err_set(ROAR_ERROR_BADFH); 
    424433  return -1; 
    425434 } 
    426435 
    427  lhandle->refc++; 
    428  
    429  if ( lhandle->refc ) 
     436 lhandle->refc--; 
     437 
     438 if ( lhandle->refc ) { 
     439  ROAR_DBG("roar_dl_unref(lhandle=%p) = 0", lhandle); 
    430440  return 0; 
     441 } 
    431442 
    432443 if ( lhandle->lib != NULL && lhandle->lib->unload != NULL ) { 
     
    457468 roar_mm_free(lhandle); 
    458469 
     470 ROAR_DBG("roar_dl_unref(lhandle=%p) = %i", lhandle, ret); 
    459471 return ret; 
    460472} 
Note: See TracChangeset for help on using the changeset viewer.