On Thu, 22 Jul 2010, Brian C. Lane wrote:
On 07/22/2010 02:15 PM, David Cantrell wrote:
+ gpointer key = NULL, value = NULL;
+ GHashTable *cmdline = readvars_parse_file("/proc/cmdline");
- if (options == NULL) {
+ if (cmdline == NULL) {
return _writeModulesConf(MODULES_CONF);
}
- while (options[i] != NULL) {
- gchar *tmpmod = NULL;
- gchar **fields = NULL;
+ g_hash_table_iter_init(&iter, cmdline);
- if (g_strstr_len(options[i], -1, "=") == NULL) {
- i++;
- continue;
- }
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ gchar *k = (gchar *) key;
+ gchar *v = (gchar *) value;
Should key and value be free'd at the end of the while loop? I'm not
sure what glib is doing to alloc these internally, and the docs aren't
clear as to what to do with the returned pointers when you're done with
them.
No, those are just pointers in to the hash table. The hash table is created
in readvars.c using g_hash_table_new_full() and given destroy functions for
the keys and values, so we just need to use g_hash_table_destroy() to clean
things up. But we should not free here because it'll create a hole in the
hash table and the iter functions won't work.
--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list