After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 620430 - memory leaks in gdm
memory leaks in gdm
Status: RESOLVED FIXED
Product: gdm
Classification: Core
Component: general
unspecified
Other All
: Normal major
: ---
Assigned To: GDM maintainers
GDM maintainers
Depends on:
Blocks:
 
 
Reported: 2010-06-03 05:37 UTC by Wang Xin
Modified: 2010-06-17 17:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix leak in gdm-server.c (1.64 KB, patch)
2010-06-03 05:50 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-session-direct.c (1.54 KB, patch)
2010-06-03 05:51 UTC, Wang Xin
none Details | Review
fix leaks in gdm-session-worker-job.c (640 bytes, patch)
2010-06-03 05:52 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-simple-slave.c (2.32 KB, patch)
2010-06-03 05:55 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-slave.c (427 bytes, patch)
2010-06-03 05:55 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-slave-proxy.c (432 bytes, patch)
2010-06-03 05:57 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-welcome-session.c (1.84 KB, patch)
2010-06-03 05:57 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-session-direct.c (7.21 KB, patch)
2010-06-04 05:48 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-session-worker.c (1.87 KB, patch)
2010-06-04 06:26 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-product-display.c (580 bytes, patch)
2010-06-04 06:41 UTC, Wang Xin
accepted-commit_now Details | Review
fix leaks in gdm-product-slave.c (712 bytes, patch)
2010-06-04 06:42 UTC, Wang Xin
accepted-commit_now Details | Review
0001-Fixes-several-memory-leaks.-By-Wang-Xin.patch (11.95 KB, patch)
2010-06-16 12:02 UTC, Pablo Castellano (IRC: pablog)
none Details | Review

Description Wang Xin 2010-06-03 05:37:42 UTC
Several memory leaks are found by using libumem on Solaris. Although the problem are found on Solaris but they should affect all other OSes.

I will post my patches later.
Comment 1 Wang Xin 2010-06-03 05:50:49 UTC
Created attachment 162603 [details] [review]
fix leak in gdm-server.c
Comment 2 Wang Xin 2010-06-03 05:51:39 UTC
Created attachment 162604 [details] [review]
fix leaks in gdm-session-direct.c
Comment 3 Wang Xin 2010-06-03 05:52:11 UTC
Created attachment 162605 [details] [review]
fix leaks in gdm-session-worker-job.c
Comment 4 Wang Xin 2010-06-03 05:55:13 UTC
Created attachment 162606 [details] [review]
fix leaks in gdm-simple-slave.c
Comment 5 Wang Xin 2010-06-03 05:55:47 UTC
Created attachment 162607 [details] [review]
fix leaks in gdm-slave.c
Comment 6 Wang Xin 2010-06-03 05:57:07 UTC
Created attachment 162608 [details] [review]
fix leaks in gdm-slave-proxy.c
Comment 7 Wang Xin 2010-06-03 05:57:35 UTC
Created attachment 162609 [details] [review]
fix leaks in gdm-welcome-session.c
Comment 8 Wang Xin 2010-06-04 05:48:56 UTC
Created attachment 162722 [details] [review]
fix leaks in gdm-session-direct.c

This patch also fixes other leaks which are not included in the original one.
Comment 9 Wang Xin 2010-06-04 06:26:10 UTC
Created attachment 162724 [details] [review]
fix leaks in gdm-session-worker.c
Comment 10 Wang Xin 2010-06-04 06:41:45 UTC
Created attachment 162725 [details] [review]
fix leaks in gdm-product-display.c
Comment 11 Wang Xin 2010-06-04 06:42:21 UTC
Created attachment 162726 [details] [review]
fix leaks in gdm-product-slave.c
Comment 12 William Jon McCann 2010-06-11 03:15:06 UTC
Review of attachment 162603 [details] [review]:

Please commit with changes suggested in the comments.

::: daemon/gdm-server.c
@@ +504,3 @@
                 str = g_strsplit (*l, "=", 2);
+                g_hash_table_insert (hash, g_strdup (str[0]), g_strdup (str[1]));
+                g_strfreev (str);

Probably a little more efficient to do:
g_hash_table_insert (hash, str[0], str[1]);
g_free (str);

@@ +977,3 @@
+        if (server->priv->chosen_hostname)
+                g_free (server->priv->chosen_hostname);
+

Looks right.  But the GDM style is to use an explicit NULL comparison and always use braces, like:
if (server->priv->command != NULL) {
    g_free (server->priv->command);
}

However, g_free already does a NULL check so these tests aren't needed.
Comment 13 William Jon McCann 2010-06-11 03:20:45 UTC
Review of attachment 162605 [details] [review]:

Please commit with the suggested change.

::: daemon/gdm-session-worker-job.c
@@ +442,3 @@
+        if (session_worker_job->priv->command)
+                g_free (session_worker_job->priv->command);
+        if (session_worker_job->priv->server_address)

As mentioned above, the ifs aren't needed here.  Hmm, we probably shouldn't need a copy of priv->command since it is constant.  Might be best to make the command a #define value.
Comment 14 William Jon McCann 2010-06-11 03:27:36 UTC
Review of attachment 162606 [details] [review]:

Please commit with that change.

::: daemon/gdm-simple-slave.c
@@ +360,1 @@
 

Interesting that we check for a NULL username here but not in the above two cases.  If the NULL is allowed we should probably "if" the above  calls to run_script.  If not then we should probably assert.  The g_free might be a little cleaner inside the if block here.
Comment 15 William Jon McCann 2010-06-11 03:29:21 UTC
Review of attachment 162607 [details] [review]:

Looks good.
Comment 16 William Jon McCann 2010-06-11 03:30:24 UTC
Review of attachment 162608 [details] [review]:

Looks good.
Comment 17 William Jon McCann 2010-06-11 03:34:43 UTC
Review of attachment 162609 [details] [review]:

Please commit with that change.

::: daemon/gdm-welcome-session.c
@@ +832,3 @@
         gboolean   res;
+        char      *std_out = NULL;
+        char      *std_err = NULL;

Please initialize variables on separate lines after the variable initialization block.  Like this:

char *str1;
char *str2;

str1 = NULL;
str2 = NULL;

And in this case do it immediately before they are used.  Right above error = NULL;
Comment 18 William Jon McCann 2010-06-11 03:42:59 UTC
Review of attachment 162722 [details] [review]:

Commit with changes.

::: daemon/gdm-session-direct.c
@@ +517,3 @@
                                          G_KEY_FILE_NONE,
                                          &error);
+        g_free (full_path);

It appears we aren't using this value.  So, better to remove it and pass in NULL.

@@ +721,3 @@
         }
 
         return get_fallback_session_name ();

Another option would be make get_fallback_session_name() not have to recompute and allocate a new string each time.  But I guess this is ok.

@@ +1997,3 @@
         }
 
         return get_default_session_name (session);

Same comment as above.

@@ +2238,3 @@
                                          G_KEY_FILE_NONE,
                                          &error);
+        g_free (full_path);

If we aren't using it please remove it.
Comment 19 William Jon McCann 2010-06-11 03:46:35 UTC
Review of attachment 162724 [details] [review]:

Commit after fixing comments.

::: daemon/gdm-session-worker.c
@@ +1727,3 @@
         if (ret) {
                 g_debug ("GdmSessionWorker: state ACCREDITED");
                 ret = TRUE;

If you free them in out: you need to set them to NULL earlier.  There is a path to reach out: before they are initialized.

@@ +2997,3 @@
+                worker->priv->hostname = NULL;
+        }
+

None of these if statements and NULL assignments are needed.  Finalize is run last.  My guess is that we once had a dispose() where they would be needed because dispose can run multiple times.

Please remove the ifs and = NULL for all of these.
Comment 20 William Jon McCann 2010-06-11 03:47:53 UTC
Review of attachment 162725 [details] [review]:

Commit after comment.

::: daemon/gdm-product-display.c
@@ +249,3 @@
+                product_display->priv->relay_address = NULL;
+        }
+

just the g_free will be fine here.  No if or = NULL.
Comment 21 William Jon McCann 2010-06-11 03:50:25 UTC
Review of attachment 162726 [details] [review]:

Looks good.

::: daemon/gdm-product-slave.c
@@ +1265,2 @@
         G_OBJECT_CLASS (gdm_product_slave_parent_class)->finalize (object);
 }

Was this already fixed in master?
Comment 22 William Jon McCann 2010-06-11 03:51:06 UTC
Since these are small enough an all related please commit these as once patch.  Thanks.
Comment 23 William Jon McCann 2010-06-15 21:21:06 UTC
Any chance someone can update these patches by tomorrow?  I'd like to get them into a new release.
Comment 24 Pablo Castellano (IRC: pablog) 2010-06-16 11:17:42 UTC
I'm working on it
Comment 25 Pablo Castellano (IRC: pablog) 2010-06-16 11:51:02 UTC
(In reply to comment #19)
> Review of attachment 162724 [details] [review]:
> 
> Commit after fixing comments.
> 
> ::: daemon/gdm-session-worker.c
> @@ +1727,3 @@
>          if (ret) {
>                  g_debug ("GdmSessionWorker: state ACCREDITED");
>                  ret = TRUE;
> 
> If you free them in out: you need to set them to NULL earlier.  There is a path
> to reach out: before they are initialized.
> 

I don't understand what do you mean.
Comment 26 Pablo Castellano (IRC: pablog) 2010-06-16 12:02:36 UTC
Created attachment 163806 [details] [review]
0001-Fixes-several-memory-leaks.-By-Wang-Xin.patch

Here it is. Patch all-in-one, but please review it too.
Comment 27 Pablo Castellano (IRC: pablog) 2010-06-16 12:03:27 UTC
Note that it lacks the #define thing.
Comment 28 William Jon McCann 2010-06-17 17:37:26 UTC
Review of attachment 163806 [details] [review]:

Looks pretty good.  I'm going to commit this with the changes I've mentioned.  Thanks.

::: daemon/gdm-server.c
@@ +512,3 @@
                 str = g_strsplit (*l, "=", 2);
                 g_hash_table_insert (hash, str[0], str[1]);
+                g_free (server->priv->chosen_hostname);

Should be g_free (str);

::: daemon/gdm-session-worker.c
@@ +1727,3 @@
         if (ret) {
                 g_debug ("GdmSessionWorker: state ACCREDITED");
                 ret = TRUE;

The first call to "goto out" is before where home and shell are initialized to NULL.  We need to move the initialization earlier.

@@ +2981,3 @@
+        g_free (worker->priv->server_address);
+        g_strfreev (worker->priv->arguments);
+        g_hash_table_destroy (worker->priv->environment);

While the g_free and g_strfreev calls check for and allow NULL values, g_hash_table_destroy does not.  So, we need to check for NULL before calling it.  Now, we know that will not happen in this class but we want to be robust against changes in other parts of the code.

::: daemon/gdm-welcome-session.c
@@ +1465,3 @@
         gdm_welcome_session_stop (welcome_session);
 
+        ck_connector_unref (welcome_session->priv->ckc);

Since there are cases where ckc can be NULL and ck_connector_unref doesn't allow NULLs we need to check it.
Comment 29 William Jon McCann 2010-06-17 17:47:41 UTC
Fixed in 2-30 and master.  Thanks!