diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2012-09-20 14:11:59 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2012-09-20 14:11:59 +0200 |
commit | a0508cbf6d021b1c7549714b9c2907146317de66 (patch) | |
tree | 77a8052618c874078641d4b8025f2a6c1d84e711 | |
parent | 671157a058df17ef7f3498fde9f51de6797ffd95 (diff) | |
download | vconsole-a0508cbf6d021b1c7549714b9c2907146317de66.tar.gz |
plug some memory holes
-rw-r--r-- | connect.c | 4 | ||||
-rw-r--r-- | domain.c | 20 | ||||
-rw-r--r-- | vconsole.c | 28 |
3 files changed, 39 insertions, 13 deletions
@@ -89,13 +89,13 @@ struct vconsole_connect *connect_init(struct vconsole_window *win, conn = g_new0(struct vconsole_connect, 1); conn->ptr = virConnectOpen(uri); - name = virConnectGetHostname(conn->ptr); if (conn->ptr == NULL) { fprintf(stderr, "Failed to open connection to %s\n", uri); g_free(conn); return NULL; } conn->win = win; + name = virConnectGetHostname(conn->ptr); virConnectDomainEventRegister(conn->ptr, connect_domain_event, conn, NULL); #if LIBVIR_VERSION_NUMBER >= 10000 /* 0.10.0 */ @@ -118,5 +118,7 @@ struct vconsole_connect *connect_init(struct vconsole_window *win, config_write(); connect_list(conn); + free(name); + return conn; } @@ -112,8 +112,6 @@ err: static void domain_log_open(struct vconsole_domain *dom) { - virDomainPtr d; - if (!dom->conn->win->vm_logging) return; if (!dom->stream) @@ -121,7 +119,6 @@ static void domain_log_open(struct vconsole_domain *dom) if (dom->logfp) return; - d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); dom->logname = g_strdup_printf("%s/vconsole/%s/%s.log", getenv("HOME"), virConnectGetHostname(dom->conn->ptr), @@ -235,6 +232,7 @@ static void domain_console_event(virStreamPtr stream, int events, void *opaque) fprintf(stderr, "%s: %s hangup\n", __func__, dom->name); domain_disconnect(dom, d); } + virDomainFree(d); } static void domain_user_input(VteTerminal *vte, gchar *buf, guint len, @@ -283,8 +281,11 @@ static void domain_update_info(struct vconsole_domain *dom, virDomainPtr d) dom->last_info = dom->info; dom->last_ts = dom->ts; + if (dom->name) + g_free(dom->name); + gettimeofday(&dom->ts, NULL); - dom->name = virDomainGetName(d); + dom->name = g_strdup(virDomainGetName(d)); dom->id = virDomainGetID(d); virDomainGetInfo(d, &dom->info); dom->saved = virDomainHasManagedSaveImage(d, 0); @@ -350,6 +351,7 @@ void domain_start(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_pause(struct vconsole_domain *dom) @@ -365,6 +367,7 @@ void domain_pause(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_save(struct vconsole_domain *dom) @@ -381,6 +384,7 @@ void domain_save(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_reboot(struct vconsole_domain *dom) @@ -396,6 +400,7 @@ void domain_reboot(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_shutdown(struct vconsole_domain *dom) @@ -411,6 +416,7 @@ void domain_shutdown(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_reset(struct vconsole_domain *dom) @@ -426,6 +432,7 @@ void domain_reset(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_kill(struct vconsole_domain *dom) @@ -441,6 +448,7 @@ void domain_kill(struct vconsole_domain *dom) fprintf(stderr, "%s: invalid guest state: %s\n", __func__, domain_state_name(dom)); } + virDomainFree(d); } void domain_free(struct vconsole_domain *dom) @@ -449,6 +457,7 @@ void domain_free(struct vconsole_domain *dom) domain_close_tab(dom, d); g_free(dom); + virDomainFree(d); } void domain_update(struct vconsole_connect *conn, @@ -544,6 +553,7 @@ void domain_update_all(struct vconsole_window *win) d = virDomainLookupByUUIDString(conn->ptr, dom->uuid); domain_update_info(dom, d); domain_update_tree_store(dom, &guest); + virDomainFree(d); rc = gtk_tree_model_iter_next(model, &guest); } rc = gtk_tree_model_iter_next(model, &host); @@ -590,6 +600,7 @@ void domain_activate(struct vconsole_domain *dom) } domain_connect(dom, d); + virDomainFree(d); } struct vconsole_domain *domain_find_current_tab(struct vconsole_window *win) @@ -628,6 +639,7 @@ void domain_close_current_tab(struct vconsole_window *win) if (dom) { d = virDomainLookupByUUIDString(dom->conn->ptr, dom->uuid); domain_close_tab(dom, d); + virDomainFree(d); } } @@ -106,12 +106,17 @@ static void menu_cb_connect_menu(GtkAction *action, gpointer userdata) struct vconsole_window *win = userdata; GError *err = NULL; char name[128]; + char *uri; if (1 != sscanf(gtk_action_get_name(action), "ConnectMenu_%127s", name)) return; if (debug) fprintf(stderr, "%s: %s\n", __func__, name); - connect_init(win, g_key_file_get_string(config, "hosts", name, &err)); + uri = g_key_file_get_string(config, "hosts", name, &err); + if (uri) { + connect_init(win, uri); + g_free(uri); + } } static void menu_cb_close_tab(GtkAction *action, gpointer userdata) @@ -624,6 +629,7 @@ static void vconsole_build_recent(struct vconsole_window *win) g_free(h); g_free(action); } + g_free(keys); /* finish */ xml = g_strdup_printf(recent_xml, entries ? entries : ""); @@ -755,16 +761,22 @@ static gint gtk_sort_iter_compare_str(GtkTreeModel *model, { gint sortcol = GPOINTER_TO_INT(userdata); char *aa,*bb; + int ret; gtk_tree_model_get(model, a, sortcol, &aa, -1); gtk_tree_model_get(model, b, sortcol, &bb, -1); - if (NULL == aa && NULL == bb) - return 0; - if (NULL == aa) - return 1; - if (NULL == bb) - return -1; - return strcmp(aa,bb); + if (NULL == aa && NULL == bb) { + ret = 0; + } else if (NULL == aa) { + ret = 1; + } else if (NULL == bb) { + ret = -1; + } else { + ret = strcmp(aa,bb); + } + g_free(aa); + g_free(bb); + return ret; } static void vconsole_tab_list_create(struct vconsole_window *win) |