lib/repo: Add (transfer) annotations to various GHashTable arguments
authorPhilip Withnall <withnall@endlessm.com>
Tue, 14 Nov 2017 16:13:13 +0000 (16:13 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 14 Nov 2017 23:13:14 +0000 (23:13 +0000)
By default, unless it’s const, an (out) GHashTable will be assumed to be
(transfer full). That means the binding needs to free all the items in
the hash table, plus the table itself.

However, all the GHashTables we use have free functions set already, so
freeing the hash table will free its items. This results in a
double-free.

Fix that by ensuring we annotate such (out) hash tables as (transfer
container). Also annotate some other hash tables as (transfer none)
where appropriate, for clarity.

This fixes OSTree.Repo.list_collection_refs() in the Python bindings.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1341
Approved by: dbnicholson

src/libostree/ostree-repo-finder.c
src/libostree/ostree-repo-refs.c
src/libostree/ostree-soup-form.c
src/libostree/ostree-soup-uri.c

index 576a690c819042d4bf3e361d2af1bf4392bbd0c2..9be176afd0d8cb6a6b4c86e57b5d7411de89b1f5 100644 (file)
@@ -432,8 +432,8 @@ G_DEFINE_BOXED_TYPE (OstreeRepoFinderResult, ostree_repo_finder_result,
  *    result
  * @priority: static priority of the result, where higher numbers indicate lower
  *    priority
- * @ref_to_checksum: (element-type OstreeCollectionRef utf8): map of collection–ref pairs
- *    to checksums provided by this result
+ * @ref_to_checksum: (element-type OstreeCollectionRef utf8) (transfer none):
+ *    map of collection–ref pairs to checksums provided by this result
  * @summary_last_modified: Unix timestamp (seconds since the epoch, UTC) when
  *    the summary file for the result was last modified, or `0` if this is unknown
  *
index 9289bb37cd7787bb160f509a5b63a15e55363785..ed4962530a45ebc9b18a82387a89a065433f2784 100644 (file)
@@ -725,7 +725,8 @@ _ostree_repo_list_refs_internal (OstreeRepo       *self,
  * ostree_repo_list_refs:
  * @self: Repo
  * @refspec_prefix: (allow-none): Only list refs which match this prefix
- * @out_all_refs: (out) (element-type utf8 utf8): Mapping from ref to checksum
+ * @out_all_refs: (out) (element-type utf8 utf8) (transfer container):
+ *    Mapping from ref to checksum
  * @cancellable: Cancellable
  * @error: Error
  *
@@ -750,7 +751,8 @@ ostree_repo_list_refs (OstreeRepo       *self,
  * ostree_repo_list_refs_ext:
  * @self: Repo
  * @refspec_prefix: (allow-none): Only list refs which match this prefix
- * @out_all_refs: (out) (element-type utf8 utf8): Mapping from ref to checksum
+ * @out_all_refs: (out) (element-type utf8 utf8) (transfer container):
+ *    Mapping from ref to checksum
  * @flags: Options controlling listing behavior
  * @cancellable: Cancellable
  * @error: Error
@@ -778,7 +780,8 @@ ostree_repo_list_refs_ext (OstreeRepo                 *self,
  * ostree_repo_remote_list_refs:
  * @self: Repo
  * @remote_name: Name of the remote.
- * @out_all_refs: (out) (element-type utf8 utf8): Mapping from ref to checksum
+ * @out_all_refs: (out) (element-type utf8 utf8) (transfer container):
+ *    Mapping from ref to checksum
  * @cancellable: Cancellable
  * @error: Error
  *
@@ -893,7 +896,8 @@ remote_list_collection_refs_process_refs (OstreeRepo   *self,
  * ostree_repo_remote_list_collection_refs:
  * @self: Repo
  * @remote_name: Name of the remote.
- * @out_all_refs: (out) (element-type OstreeCollectionRef utf8): Mapping from collection–ref to checksum
+ * @out_all_refs: (out) (element-type OstreeCollectionRef utf8) (transfer container):
+ *    Mapping from collection–ref to checksum
  * @cancellable: Cancellable
  * @error: Error
  *
@@ -1165,7 +1169,8 @@ _ostree_repo_update_collection_refs (OstreeRepo        *self,
  * ostree_repo_list_collection_refs:
  * @self: Repo
  * @match_collection_id: (nullable): If non-%NULL, only list refs from this collection
- * @out_all_refs: (out) (element-type OstreeCollectionRef utf8): Mapping from collection–ref to checksum
+ * @out_all_refs: (out) (element-type OstreeCollectionRef utf8) (transfer container):
+ *    Mapping from collection–ref to checksum
  * @flags: Options controlling listing behavior
  * @cancellable: Cancellable
  * @error: Error
index 74f9c7bb049f04c269951af81d169ba0ae1e2c90..dfaffb9617b5ebee7684c6a5eda50dfd43c32495 100644 (file)
@@ -82,7 +82,7 @@ encode_pair (GString *str, const char *name, const char *value)
 
 /**
  * soup_form_encode_hash:
- * @form_data_set: (element-type utf8 utf8): a hash table containing
+ * @form_data_set: (element-type utf8 utf8) (transfer none): a hash table containing
  * name/value pairs (as strings)
  *
  * Encodes @form_data_set into a value of type
index 97f74636b6e5c772a681480609f6f6afd9e776e1..a3fa2acc12c2b8e5383bb25318f509fcaf5e17b1 100644 (file)
@@ -1281,7 +1281,7 @@ soup_uri_set_query (SoupURI *uri, const char *query)
 /**
  * soup_uri_set_query_from_form:
  * @uri: a #SoupURI
- * @form: (element-type utf8 utf8): a #GHashTable containing HTML form
+ * @form: (element-type utf8 utf8) (transfer none): a #GHashTable containing HTML form
  * information
  *
  * Sets @uri's query to the result of encoding @form according to the