Matthew Leeds
51b822787e
gvariant-core: Add a note about memory safety of children
...
When g_variant_get_child() is called on a variant which has not been
serialized, it serializes it which includes a call to
g_variant_release_children() and therefore means that any children
previously retrieved from the variant are no longer valid (unless
another reference is held on them) and consequently values borrowed from
those children are no longer safe to access. Add a note to the
g_variant_get_child_value() documentation to explain this.
Alternatively, we could say that after the child is freed, values
borrowed from it are no longer valid. But we already have an
implementation which hasn't changed in years which lets them stay valid
if the variant was serialized before the first
g_variant_get_child_value() call.
Here's a demonstration of the memory error:
static const char *get_first_child (GVariant *v) {
g_autoptr(GVariant) child_v = g_variant_get_child_value (v, 0);
return g_variant_get_string (child_v, NULL);
}
int main(int argc, char **argv) {
g_autoptr(GVariant) v = g_variant_new("(@ss)", g_variant_new_string ("hello"), "world");
const char *child1 = get_first_child (v);
const char *child2;
g_variant_get_child (v, 1, "&s", &child2);
printf ("%s\n", child1); // this is a memory error
return 0;
}
2020-04-27 17:31:53 -07:00
..
2020-01-15 23:18:33 +02:00
2019-01-16 10:24:11 -05:00
2019-01-15 15:11:43 +00:00
2020-02-07 17:12:35 +00:00
2020-02-27 10:33:45 +00:00
2019-01-15 15:11:43 +00:00
2020-04-03 16:30:27 +02:00
2020-02-27 10:33:45 +00:00
2019-08-24 19:14:05 +00:00
2017-05-24 11:58:19 +02:00
2019-07-10 10:10:58 -04:00
2020-03-03 14:32:37 +00:00
2019-10-07 14:38:24 +02:00
2019-07-29 12:27:29 +01:00
2019-07-29 12:27:29 +01:00
2017-05-24 11:58:19 +02:00
2019-07-26 02:11:35 +01:00
2019-11-20 12:12:04 +00:00
2019-11-21 11:02:14 +00:00
2018-08-22 10:37:15 +01:00
2020-01-15 13:15:54 +00:00
2017-05-24 11:58:19 +02:00
2019-09-21 10:48:23 +02:00
2017-05-24 11:58:19 +02:00
2019-11-05 10:08:45 +00:00
2018-08-22 11:18:02 +01:00
2018-06-02 09:45:55 +02:00
2019-11-04 15:10:24 +00:00
2017-05-24 11:58:19 +02:00
2019-10-11 11:47:42 +01:00
2019-05-27 17:51:40 +00:00
2017-05-24 11:58:19 +02:00
2019-09-05 13:51:27 +01:00
2017-05-24 11:58:19 +02:00
2019-04-25 12:55:04 +08:00
2019-04-12 11:12:28 +05:30
2018-08-22 11:18:02 +01:00
2019-01-28 15:24:06 +01:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2020-03-04 11:21:17 +01:00
2019-07-29 12:27:29 +01:00
2019-11-21 09:14:39 +01:00
2019-07-29 12:27:29 +01:00
2019-01-24 11:31:38 +01:00
2017-05-24 11:58:19 +02:00
2016-09-21 18:30:52 +02:00
2020-01-21 12:07:17 +00:00
2017-05-24 11:58:19 +02:00
2020-02-26 20:06:13 +01:00
2017-05-24 11:58:19 +02:00
2019-08-08 02:32:46 +02:00
2019-05-30 10:38:45 +01:00
2019-01-15 15:11:43 +00:00
2017-05-24 11:58:19 +02:00
2020-02-24 10:21:40 +00:00
2019-05-30 10:38:45 +01:00
2019-08-24 19:14:05 +00:00
2017-05-24 11:58:19 +02:00
2017-11-12 16:36:16 +01:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2020-02-24 14:12:30 +00:00
2019-08-24 19:14:05 +00:00
2019-03-17 19:05:34 +01:00
2018-04-27 16:46:19 +01:00
2019-09-05 13:51:27 +01:00
2018-08-22 11:18:02 +01:00
2019-11-05 14:28:41 -08:00
2018-08-25 23:59:45 +01:00
2019-09-05 14:16:58 +01:00
2019-12-10 17:58:16 +01:00
2019-03-06 11:41:56 +00:00
2019-03-06 11:41:56 +00:00
2019-12-11 11:48:41 +00:00
2017-11-01 12:46:38 +00:00
2019-06-18 17:29:36 +08:00
2020-04-01 12:39:52 +02:00
2019-11-26 12:17:04 +00:00
2019-12-11 11:48:41 +00:00
2018-01-04 22:19:30 +01:00
2019-08-24 19:14:05 +00:00
2019-05-30 10:38:45 +01:00
2013-01-13 13:11:57 -05:00
2020-02-07 14:09:41 +00:00
2019-11-25 13:09:25 +01:00
2020-03-17 22:00:54 +03:00
2017-05-24 11:58:19 +02:00
2020-02-11 10:53:56 +02:00
2020-01-15 16:56:34 +01:00
2019-03-15 21:30:22 +01:00
2018-08-22 11:18:02 +01:00
2019-09-18 17:06:20 +01:00
2017-05-24 11:58:19 +02:00
2019-09-16 14:03:07 +01:00
2019-08-26 18:50:16 +03:00
2019-09-05 13:51:27 +01:00
2019-10-09 16:39:31 +02:00
2008-04-08 02:59:05 +00:00
2017-11-28 14:16:25 +00:00
2019-06-25 09:19:49 +02:00
2019-10-31 13:54:51 +00:00
2019-06-03 10:57:18 +01:00
2019-02-01 09:10:02 -06:00
2019-11-21 13:07:08 +01:00
2017-05-24 11:58:19 +02:00
2018-12-28 13:28:43 +01:00
2017-05-24 11:58:19 +02:00
2019-03-15 21:30:22 +01:00
2017-05-24 11:58:19 +02:00
2019-10-07 17:29:34 +01:00
2017-05-24 11:58:19 +02:00
2019-08-20 17:19:26 +02:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2019-09-21 10:48:23 +02:00
2017-05-24 11:58:19 +02:00
2019-05-02 13:53:09 +01:00
2019-05-01 13:01:14 -07:00
2019-09-05 13:51:27 +01:00
2017-05-24 11:58:19 +02:00
2019-07-10 10:10:58 -04:00
2018-08-22 11:18:02 +01:00
2018-12-18 11:18:43 +00:00
2018-11-08 16:04:51 +01:00
2018-11-08 16:04:51 +01:00
2018-07-30 23:06:23 +05:30
2018-12-17 13:53:34 +00:00
2019-08-24 19:14:05 +00:00
2017-10-06 12:49:12 +01:00
2020-03-04 11:21:17 +01:00
2019-05-30 10:38:45 +01:00
2020-03-18 14:50:36 +00:00
2019-04-26 12:12:31 +01:00
2017-05-24 11:58:19 +02:00
2020-03-04 11:21:17 +01:00
2017-05-24 11:58:19 +02:00
2020-03-04 11:21:17 +01:00
2018-08-22 11:18:02 +01:00
2020-02-07 14:09:41 +00:00
2019-11-25 13:09:25 +01:00
2018-06-12 16:13:51 +01:00
2019-08-24 19:14:05 +00:00
2019-08-24 19:14:05 +00:00
2020-03-04 11:21:17 +01:00
2019-05-30 10:38:45 +01:00
2018-10-10 19:19:18 +00:00
2020-01-30 01:56:56 +00:00
2019-09-18 10:47:23 +02:00
2020-01-30 01:56:56 +00:00
2019-11-21 10:44:48 +01:00
2018-12-17 17:16:03 +00:00
2019-10-07 17:29:34 +01:00
2019-05-30 10:38:45 +01:00
2017-10-26 12:27:17 +01:00
2017-05-24 11:58:19 +02:00
2019-05-14 12:14:54 +01:00
2019-05-14 12:14:54 +01:00
2019-09-30 12:05:55 +01:00
2019-10-28 17:36:36 +00:00
2020-02-24 12:07:25 +02:00
2020-01-19 10:47:52 +02:00
2020-01-21 11:56:34 +00:00
2020-01-31 16:00:28 +01:00
2020-01-25 11:08:22 +02:00
2017-05-24 11:58:19 +02:00
2020-01-21 11:56:34 +00:00
2019-07-29 12:27:29 +01:00
2019-07-29 12:27:29 +01:00
2020-02-24 10:26:01 +00:00
2018-04-13 15:25:26 +01:00
2014-02-20 18:27:24 -05:00
2018-07-30 21:15:22 +01:00
2019-05-30 10:39:11 +01:00
2019-05-30 10:39:11 +01:00
2019-07-23 11:41:42 +00:00
2017-05-24 11:58:19 +02:00
2020-03-31 23:22:26 +03:00
2017-05-24 11:58:19 +02:00
2020-03-18 14:50:36 +00:00
2020-03-18 14:50:36 +00:00
2020-03-18 14:50:36 +00:00
2017-05-24 11:58:19 +02:00
2019-10-08 13:50:13 +01:00
2020-03-18 14:50:36 +00:00
2020-03-31 14:18:32 +01:00
2020-03-18 14:50:36 +00:00
2020-03-18 14:50:36 +00:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2019-11-14 18:38:03 +00:00
2020-01-15 14:07:20 +01:00
2019-09-27 15:47:03 +12:00
2018-12-17 17:16:03 +00:00
2019-11-25 10:10:36 +00:00
2017-02-06 14:40:38 +01:00
2018-05-28 09:22:55 -04:00
2020-04-27 17:31:53 -07:00
2017-05-24 11:58:19 +02:00
2018-10-23 17:01:51 +13:00
2019-10-30 15:37:39 +00:00
2018-11-06 12:49:25 +00:00
2018-11-06 12:49:25 +00:00
2020-03-04 11:21:17 +01:00
2019-10-18 13:53:18 +01:00
2019-03-08 19:46:21 +00:00
2018-10-23 17:01:51 +13:00
2019-08-24 19:14:05 +00:00
2018-10-23 17:01:51 +13:00
2017-05-24 11:58:19 +02:00
2017-05-24 11:58:19 +02:00
2020-03-04 14:46:28 +00:00
2018-04-27 16:46:19 +01:00
2017-05-24 11:58:19 +02:00
2019-08-10 21:56:33 +02:00
2020-02-18 23:24:52 +05:30
2017-07-12 22:36:30 +02:00
2016-05-23 10:52:10 -04:00
2020-04-05 00:34:04 -04:00
2018-07-12 23:48:41 +02:00
2020-04-03 13:03:31 +01:00
2016-08-13 10:31:26 +02:00