Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/common/helpers.py
    ... ... @@ -1745,10 +1745,10 @@ class Observable:
    1745 1745
     def write_file_async(path, data, callback, user_data=None):
    
    1746 1746
         file = Gio.File.new_for_path(str(path))
    
    1747 1747
         file.create_async(Gio.FileCreateFlags.PRIVATE,
    
    1748
    -                          GLib.PRIORITY_DEFAULT,
    
    1749
    -                          None,
    
    1750
    -                          _on_file_created,
    
    1751
    -                          (callback, data, user_data))
    
    1748
    +                      GLib.PRIORITY_DEFAULT,
    
    1749
    +                      None,
    
    1750
    +                      _on_file_created,
    
    1751
    +                      (callback, data, user_data))
    
    1752 1752
     
    
    1753 1753
     def _on_file_created(file, result, user_data):
    
    1754 1754
         callback, data, user_data = user_data
    
    ... ... @@ -1756,16 +1756,18 @@ def _on_file_created(file, result, user_data):
    1756 1756
             outputstream = file.create_finish(result)
    
    1757 1757
         except GLib.Error as error:
    
    1758 1758
             callback(False, error, user_data)
    
    1759
    -        return
    
    1760 1759
     
    
    1760
    +    # Pass data as user_data to the callback, because
    
    1761
    +    # write_all_async() takes not reference to the data
    
    1762
    +    # and python gc collects it before the data are written
    
    1761 1763
         outputstream.write_all_async(data,
    
    1762 1764
                                      GLib.PRIORITY_DEFAULT,
    
    1763 1765
                                      None,
    
    1764 1766
                                      _on_write_finished,
    
    1765
    -                                 (callback, user_data))
    
    1767
    +                                 (callback, data, user_data))
    
    1766 1768
     
    
    1767 1769
     def _on_write_finished(outputstream, result, user_data):
    
    1768
    -    callback, user_data = user_data
    
    1770
    +    callback, _data, user_data = user_data
    
    1769 1771
         try:
    
    1770 1772
             successful, _bytes_written = outputstream.write_all_finish(result)
    
    1771 1773
         except GLib.Error as error: