Advertisement
Guest User

Untitled

a guest
Sep 24th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. // -std=c++11 -Wall -Wextra
  2.  
  3. #include <iostream>
  4. #include <functional>
  5. #include <assert.h>
  6.  
  7. #include <ostree.h>
  8.  
  9. using namespace std;
  10.  
  11. struct Defer
  12. {
  13.   function<void()> _f;
  14.  
  15.   Defer(function<void()> f)
  16.   :_f(std::move(f))
  17.   {
  18.   }
  19.  
  20.   ~Defer()
  21.   {
  22.     _f();
  23.   }
  24. };
  25.  
  26. int main(int argc, char **argv)
  27. {
  28.   GFile *path(g_file_new_for_path(argv[1]));
  29.  
  30.   Defer d0([&path] {
  31.     g_object_unref(path);
  32.   });
  33.  
  34.   OstreeRepo *repo(ostree_repo_new(path));
  35.  
  36.   assert(repo);
  37.  
  38.   Defer d([&repo] {
  39.     g_object_unref(repo);
  40.   });
  41.  
  42.   {
  43.     GError *error(nullptr);
  44.  
  45.     Defer d([&error] {
  46.       if (error) {
  47.         g_error_free(error);
  48.       }
  49.     });
  50.  
  51.     if (!ostree_repo_open(repo,nullptr,&error)) {
  52.       cerr << "Error opening repository: " << error->message << endl;
  53.       return 1;
  54.     }
  55.  
  56.     // FIXME: when there is no errors on open(), there is a leak of 72 bytes on it
  57.   }
  58.  
  59.   return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement