[Bugs] #1550 UNSP: file descriptor leak in filestore.retrieve()

Sugar Labs Bugs bugtracker-noreply at sugarlabs.org
Thu Nov 12 05:43:11 EST 2009


#1550: file descriptor leak in filestore.retrieve()
------------------------------------------+---------------------------------
    Reporter:  sascha_silbe               |          Owner:  tomeu            
        Type:  defect                     |         Status:  new              
    Priority:  Unspecified by Maintainer  |      Milestone:  0.88             
   Component:  sugar-datastore            |        Version:  Git as of bugdate
    Severity:  Major                      |       Keywords:                   
Distribution:  Unspecified                |   Status_field:  Assigned         
------------------------------------------+---------------------------------
 filestore.retrieve() contains a file descriptor leak:

 {{{
         attempt = 1
         while os.path.exists(destination_path):
             if attempt > 10:
                 fd_, destination_path = tempfile.mkstemp(prefix=uid,
                                                          suffix=extension,
 dir=destination_dir)
                 del fd_
                 os.unlink(destination_path)
                 break
             else:
                 file_name = '%s_%s%s' % (uid, attempt, extension)
                 destination_path = os.path.join(destination_dir,
 file_name)
                 attempt += 1
 }}}

 Since fd_ is a plain integer (i.e. not a file object), "del fd_" will not
 close the file descriptor, but leave it open.

 What's the reason for having two different ways of choosing names, BTW?
 Why don't we just use a single mkstemp() call and be done with it?

-- 
Ticket URL: <http://bugs.sugarlabs.org/ticket/1550>
Sugar Labs <http://sugarlabs.org/>
Sugar Labs bug tracking system


More information about the Bugs mailing list