[virt-tools-list] [remote-viewer v1] remote-viewer: fix free on dangling pointer

Victor Toso victortoso at redhat.com
Mon Sep 30 08:05:26 UTC 2019


Hi,

On Fri, Sep 27, 2019 at 04:21:58PM -0300, Eduardo Lima (Etrunko) wrote:
> On 9/27/19 10:35 AM, Victor Toso wrote:
> >   static gboolean
> > -create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
> > +create_ovirt_session(VirtViewerApp *app, GError **err)
> >   {
> >       OvirtProxy *proxy = NULL;
> >       OvirtApi *api = NULL;
> > @@ -421,9 +421,11 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
> >       gchar *ticket = NULL;
> >       gchar *host_subject = NULL;
> >       gchar *guid = NULL;
> > +    gchar *guri = NULL;
> >       g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
> > +    g_object_get(app, "guri", &guri, NULL);
> >       if (!parse_ovirt_uri(uri, &rest_uri, &vm_name, &username)) {
> 
> Patch does not build. Are you sure your configure passes the ovirt checks?

I'm sure that I build without ovirt :)
Fixed, I'll send a v2. Many thanks for checking!

> remote-viewer.c: In function 'create_ovirt_session':
> remote-viewer.c:430:26: error: 'uri' undeclared (first use in this
> function); did you mean 'guri'?
>   430 |     if (!parse_ovirt_uri(uri, &rest_uri, &vm_name, &username)) {
>       |                          ^~~
>       |                          guri
> remote-viewer.c:430:26: note: each undeclared identifier is reported only
> once for each function it appears in
> 
> 
> 
> >           g_set_error_literal(&error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_FAILED,
> >                               _("failed to parse ovirt uri"));
> > @@ -561,6 +563,7 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
> >       success = TRUE;
> >   error:
> > +    g_free(guri);
> >       g_free(username);
> >       g_free(rest_uri);
> >       g_free(vm_name);
> > @@ -645,17 +648,16 @@ remote_viewer_recent_add(gchar *uri, const gchar *mime_type)
> >   static void
> >   remote_viewer_session_connected(VirtViewerSession *session,
> > -                                gchar *guri)
> > +                                VirtViewerApp *app)
> >   {
> >       gchar *uri = virt_viewer_session_get_uri(session);
> >       const gchar *mime = virt_viewer_session_mime_type(session);
> >       if (uri == NULL)
> > -        uri = g_strdup(guri);
> > +        g_object_get(app, "guri", &uri, NULL);
> >       remote_viewer_recent_add(uri, mime);
> >       g_free(uri);
> > -    g_free(guri);
> >   }
> >   static gchar *
> > @@ -675,14 +677,14 @@ read_all_stdin(gsize *len, GError **err)
> >   }
> >   static gboolean
> > -remote_viewer_initial_connect(RemoteViewer *self, const gchar *type, const gchar *guri,
> > +remote_viewer_initial_connect(RemoteViewer *self, const gchar *type,
> >                                 VirtViewerFile *vvfile, GError **error)
> >   {
> >       VirtViewerApp *app = VIRT_VIEWER_APP(self);
> >   #ifdef HAVE_OVIRT
> >       if (g_strcmp0(type, "ovirt") == 0) {
> > -        if (!create_ovirt_session(app, guri, error)) {
> > +        if (!create_ovirt_session(app, error)) {
> >               g_prefix_error(error, _("Couldn't open oVirt session: "));
> >               return FALSE;
> >           }
> > @@ -694,7 +696,7 @@ remote_viewer_initial_connect(RemoteViewer *self, const gchar *type, const gchar
> >       }
> >       g_signal_connect(virt_viewer_app_get_session(app), "session-connected",
> > -                     G_CALLBACK(remote_viewer_session_connected), g_strdup(guri));
> > +                     G_CALLBACK(remote_viewer_session_connected), app);
> >       virt_viewer_session_set_file(virt_viewer_app_get_session(app), vvfile);
> >   #ifdef HAVE_OVIRT
> > @@ -787,7 +789,7 @@ retry_dialog:
> >                                   _("Cannot determine the connection type from URI"));
> >               goto cleanup;
> >           }
> > -        if (!remote_viewer_initial_connect(self, type, guri, vvfile, &error))
> > +        if (!remote_viewer_initial_connect(self, type, vvfile, &error))
> >               goto cleanup;
> >       }
> > 
> 
> 
> -- 
> Eduardo de Barros Lima (Etrunko)
> Software Engineer - Red Hat
> etrunko at redhat.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20190930/c2e1466f/attachment.sig>


More information about the virt-tools-list mailing list