~lightdm-team/lightdm/trunk

« back to all changes in this revision

Viewing changes to tests/src/Xvnc.c

  • Committer: Robert Ancell
  • Date: 2017-09-27 21:35:55 UTC
  • Revision ID: robert.ancell@canonical.com-20170927213555-08scdccrxw9epf5f
Use g_auto to automatically free memory

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
{
39
39
    if (lock_path)
40
40
        unlink (lock_path);
41
 
    if (xserver)
42
 
        g_object_unref (xserver);
 
41
    g_clear_object (&xserver);
43
42
}
44
43
 
45
44
static void
91
90
    gchar buffer[1024];
92
91
    gsize n_read;
93
92
    GIOStatus status;
94
 
    GError *error = NULL;
 
93
    g_autoptr(GError) error = NULL;
95
94
 
96
95
    status = g_io_channel_read_chars (channel, buffer, 1023, &n_read, &error);
97
96
    if (error)
98
97
        g_warning ("Error reading from VNC client: %s", error->message);
99
 
    g_clear_error (&error);
100
98
 
101
99
    if (status == G_IO_STATUS_NORMAL)
102
100
    {
142
140
main (int argc, char **argv)
143
141
{
144
142
    int i;
145
 
    char *pid_string;
 
143
    g_autofree gchar *pid_string = NULL;
146
144
    gboolean use_inetd = FALSE;
147
145
    gboolean has_option = FALSE;
148
 
    gchar *geometry = g_strdup ("640x480");
 
146
    const gchar *geometry = "640x480";
149
147
    gint depth = 8;
150
 
    gchar *lock_filename;
 
148
    g_autofree gchar *lock_filename = NULL;
151
149
    int lock_file;
152
150
 
153
151
#if !defined(GLIB_VERSION_2_36)
184
182
        }
185
183
        else if (strcmp (arg, "-geometry") == 0)
186
184
        {
187
 
            g_free (geometry);
188
 
            geometry = g_strdup (argv[i+1]);
 
185
            geometry = argv[i+1];
189
186
            i++;
190
187
        }
191
188
        else if (strcmp (arg, "-depth") == 0)
241
238
 
242
239
    lock_filename = g_strdup_printf (".X%d-lock", display_number);
243
240
    lock_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", lock_filename, NULL);
244
 
    g_free (lock_filename);
245
241
    lock_file = open (lock_path, O_CREAT | O_EXCL | O_WRONLY, 0444);
246
242
    if (lock_file < 0)
247
243
    {
248
 
        char *lock_contents = NULL;
 
244
        g_autofree gchar *lock_contents = NULL;
249
245
 
250
246
        if (g_file_get_contents (lock_path, &lock_contents, NULL, NULL))
251
247
        {
252
 
            gchar *proc_filename;
 
248
            g_autofree gchar *proc_filename = NULL;
253
249
            pid_t pid;
254
250
 
255
251
            pid = atol (lock_contents);
256
 
            g_free (lock_contents);
257
252
 
258
253
            proc_filename = g_strdup_printf ("/proc/%d", pid);
259
254
            if (!g_file_test (proc_filename, G_FILE_TEST_EXISTS))
260
255
            {
261
 
                gchar *socket_dir;
262
 
                gchar *socket_filename;
263
 
                gchar *socket_path;
 
256
                g_autofree gchar *socket_dir = NULL;
 
257
                g_autofree gchar *socket_filename = NULL;
 
258
                g_autofree gchar *socket_path = NULL;
264
259
 
265
260
                socket_dir = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", ".X11-unix", NULL);
266
261
                g_mkdir_with_parents (socket_dir, 0755);
271
266
                g_printerr ("Breaking lock on non-existant process %d\n", pid);
272
267
                unlink (lock_path);
273
268
                unlink (socket_path);
274
 
 
275
 
                g_free (socket_dir);
276
 
                g_free (socket_filename);
277
 
                g_free (socket_path);
278
269
            }
279
 
            g_free (proc_filename);
280
270
 
281
271
            lock_file = open (lock_path, O_CREAT | O_EXCL | O_WRONLY, 0444);
282
272
        }
288
278
                 "Server is already active for display %d\n"
289
279
                 "      If this server is no longer running, remove %s\n"
290
280
                 "      and start again.\n", display_number, lock_path);
291
 
        g_free (lock_path);
292
 
        lock_path = NULL;
 
281
        g_clear_pointer (&lock_path, g_free);
293
282
        return EXIT_FAILURE;
294
283
    }
295
284
    pid_string = g_strdup_printf ("%10ld", (long) getpid ());
298
287
        g_warning ("Error writing PID file: %s", strerror (errno));
299
288
        return EXIT_FAILURE;
300
289
    }
301
 
    g_free (pid_string);
302
290
 
303
291
    if (!x_server_start (xserver))
304
292
        return EXIT_FAILURE;