[libvirt] [libvirt-designer 1/4] virtxml: Make global var local

OsinfoLoader is declared as a global variable in virtxml.c but is only used in one function, so it can be made local. --- examples/virtxml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/virtxml.c b/examples/virtxml.c index 2918ee0..18b0456 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -35,7 +35,6 @@ GList *disk_str_list = NULL; GList *iface_str_list = NULL; -OsinfoLoader *loader = NULL; OsinfoDb *db = NULL; #define print_error(...) \ @@ -65,6 +64,7 @@ load_osinfo(void) { GError *err = NULL; gboolean ret = FALSE; + OsinfoLoader *loader = NULL; loader = osinfo_loader_new(); osinfo_loader_process_default_path(loader, &err); -- 1.8.1

virtxml is using osinfo_db_guess_os_from_media for that which is deprecated. --- examples/virtxml.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/virtxml.c b/examples/virtxml.c index 18b0456..d719e5f 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -364,7 +364,6 @@ guess_os_from_disk(GList *disk_list) char *path = (char *) list_it->data; char *sep = strchr(path, ','); OsinfoMedia *media = NULL; - OsinfoMedia *matched_media = NULL; if (sep) path = g_strndup(path, sep-path); @@ -373,15 +372,13 @@ guess_os_from_disk(GList *disk_list) if (!media) continue; - ret = osinfo_db_guess_os_from_media(db, media, &matched_media); + if (osinfo_db_identify_media(db, media)) { + g_object_get(G_OBJECT(media), "os", &ret, NULL); + break; + } if (sep) g_free(path); - - if (ret) { - g_object_ref(ret); - break; - } } return ret; -- 1.8.1

On 22.01.2013 16:48, Christophe Fergeau wrote:
virtxml is using osinfo_db_guess_os_from_media for that which is deprecated. --- examples/virtxml.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/examples/virtxml.c b/examples/virtxml.c index 18b0456..d719e5f 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -364,7 +364,6 @@ guess_os_from_disk(GList *disk_list) char *path = (char *) list_it->data; char *sep = strchr(path, ','); OsinfoMedia *media = NULL; - OsinfoMedia *matched_media = NULL;
if (sep) path = g_strndup(path, sep-path); @@ -373,15 +372,13 @@ guess_os_from_disk(GList *disk_list) if (!media) continue;
- ret = osinfo_db_guess_os_from_media(db, media, &matched_media); + if (osinfo_db_identify_media(db, media)) {
The osinfo_db_identify_media API was introduced in libosinfo-0.2.3 if I am not mistaken. However, in configure.ac we still require the 0.0.5 version.
+ g_object_get(G_OBJECT(media), "os", &ret, NULL); + break; + }
if (sep) g_free(path); - - if (ret) { - g_object_ref(ret); - break; - } }
return ret;
ACK if you squash this in: diff --git a/configure.ac b/configure.ac index f6937c9..a9c5c34 100644 --- a/configure.ac +++ b/configure.ac @@ -10,7 +10,7 @@ AC_CANONICAL_HOST AM_SILENT_RULES([yes]) -LIBOSINFO_REQUIRED=0.0.5 +LIBOSINFO_REQUIRED=0.2.3 LIBVIRT_GCONFIG_REQUIRED=0.0.9 LIBVIRT_GOBJECT_REQUIRED=0.1.3 GOBJECT_INTROSPECTION_REQUIRED=0.10.8 Michal

All memory was not cleaned up properly upon exit, and a string could be leaked from guess_os_from_disk when we issue a continue/break early during the loop iteration. --- examples/virtxml.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/virtxml.c b/examples/virtxml.c index d719e5f..e577911 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -369,6 +369,10 @@ guess_os_from_disk(GList *disk_list) path = g_strndup(path, sep-path); media = osinfo_media_create_from_location(path, NULL, NULL); + + if (sep) + g_free(path); + if (!media) continue; @@ -376,9 +380,6 @@ guess_os_from_disk(GList *disk_list) g_object_get(G_OBJECT(media), "os", &ret, NULL); break; } - - if (sep) - g_free(path); } return ret; @@ -595,12 +596,22 @@ main(int argc, char *argv[]) xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(config)); g_printf("%s\n", xml); + g_free(xml); ret = EXIT_SUCCESS; cleanup: + if (os) + g_object_unref(G_OBJECT(os)); + if (platform) + g_object_unref(G_OBJECT(platform)); + if (caps) + g_object_unref(G_OBJECT(caps)); + if (domain) + g_object_unref(G_OBJECT(domain)); if (conn) gvir_connection_close(conn); + return ret; } -- 1.8.1

On 22.01.2013 16:48, Christophe Fergeau wrote:
All memory was not cleaned up properly upon exit, and a string could be leaked from guess_os_from_disk when we issue a continue/break early during the loop iteration. --- examples/virtxml.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
ACK Michal

An error will be reported even if loading partially worked (for example when the system DB could be loaded, but the user DB failed to load). Since the code will still work correctly even if the DB could not be loaded at all, we can ignore the error when DB loading failed. (code still works but virtxml cannot do a lot of useful stuff as it needs an OS and an hypervisor). --- examples/virtxml.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/virtxml.c b/examples/virtxml.c index e577911..09f49cf 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -70,14 +70,13 @@ load_osinfo(void) osinfo_loader_process_default_path(loader, &err); if (err) { print_error("Unable to load default libosinfo DB: %s", err->message); - goto cleanup; + g_clear_error(&err); } db = osinfo_loader_get_db(loader); g_object_ref(db); ret = TRUE; -cleanup: g_object_unref(loader); return ret; } -- 1.8.1

On 22.01.2013 16:48, Christophe Fergeau wrote:
An error will be reported even if loading partially worked (for example when the system DB could be loaded, but the user DB failed to load). Since the code will still work correctly even if the DB could not be loaded at all, we can ignore the error when DB loading failed. (code still works but virtxml cannot do a lot of useful stuff as it needs an OS and an hypervisor). --- examples/virtxml.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
ACK Michal
participants (2)
-
Christophe Fergeau
-
Michal Privoznik