Changeset cfce4d127184f4e4f334976151a0f80594bb5e22 in libusb


Ignore:
Timestamp:
02/15/10 21:10:08 (7 months ago)
Author:
Daniel Drake <dan@…>
Children:
68af9f8d731f700267335941a8214d34ab518cc8
Parents:
161893cfbefefe315f657677705abe090fc526f2
git-author:
Nathan Hjelm <hjelmn@mac.com> / 2010-02-15T14:10:08Z-0600
git-committer:
Daniel Drake <dan@reactivated.net> / 2010-02-15T14:10:08Z-0600
Message:

Darwin: fix memory leak in process_device

Credit to Mike Colagrosso for finding this bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libusb/os/darwin_usb.c

    r161893 rcfce4d  
    442442  UInt8                 bDeviceClass, bDeviceSubClass; 
    443443  IOUSBDevRequest      req; 
    444   int ret; 
     444  int ret, need_unref = 0; 
    445445 
    446446  dev = usbi_get_device_by_session_id(ctx, locationID); 
    447447  if (!dev) { 
    448     _usbi_log (ctx, LOG_LEVEL_INFO, "allocating new device for location 0x%08x", locationID); 
     448    usbi_info (ctx, "allocating new device for location 0x%08x", locationID); 
    449449    dev = usbi_alloc_device(ctx, locationID); 
     450    need_unref = 1; 
    450451    if (!dev) 
    451452      return LIBUSB_ERROR_NO_MEM; 
     
    498499 
    499500    if (ret != kIOReturnSuccess) { 
    500       _usbi_log (ctx, LOG_LEVEL_WARNING, "could not retrieve device descriptor: %s. skipping device", darwin_error_str (ret)); 
    501       libusb_unref_device(dev); 
     501      usbi_warn (ctx, "could not retrieve device descriptor: %s. skipping device", darwin_error_str (ret)); 
     502      if (need_unref) 
     503        libusb_unref_device(dev); 
    502504      return -1; 
    503505    } 
     
    523525 
    524526    if (ret < 0) { 
    525       libusb_unref_device(dev); 
     527      if (need_unref) 
     528        libusb_unref_device(dev); 
    526529      return -1; 
    527530    } 
     
    529532    priv = (struct darwin_device_priv *)dev->os_priv; 
    530533 
    531     _usbi_log (ctx, LOG_LEVEL_INFO, "using existing device for location 0x%08x", locationID); 
     534    usbi_info (ctx, "using existing device for location 0x%08x", locationID); 
    532535  } 
    533536 
     
    539542  *_discdevs = discdevs; 
    540543   
    541   _usbi_log (ctx, LOG_LEVEL_INFO, "found device with address %d at %s", dev->device_address, priv->sys_path); 
    542    
     544  usbi_info (ctx, "found device with address %d at %s", dev->device_address, priv->sys_path); 
     545   
     546  if (need_unref) 
     547    libusb_unref_device(dev); 
     548 
    543549  return 0; 
    544550} 
Note: See TracChangeset for help on using the changeset viewer.