[PATCH] plugs GnomeVFSSocket leaks in ftp/http method
- From: Thomas Cataldo <thomas cataldo aliacom fr>
- To: gnome-vfs-list gnome org
- Subject: [PATCH] plugs GnomeVFSSocket leaks in ftp/http method
- Date: Fri, 30 Jan 2004 03:00:53 +0100
Hi,
The attached patch was made after some valgrind/gnomevfs-(cat|ls) tests
agains ftp and http urls.
By the way, as my previous patch against the nntp method was not
reviewed, could you tell me if this list is the right place to send
patches, or if a bug report is a better way.
cheers,
Thomas.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v
retrieving revision 1.1716
diff -u -r1.1716 ChangeLog
--- ChangeLog 27 Jan 2004 18:59:08 -0000 1.1716
+++ ChangeLog 30 Jan 2004 01:55:40 -0000
@@ -1,3 +1,12 @@
+2004-01-30 Thomas Cataldo <thomas cataldo aliacom fr>
+
+ plug some gnome_vfs_socket leaks.
+
+ * libgnomevfs/gnome-vfs-socket-buffer.c:
+ (gnome_vfs_socket_buffer_destroy):
+ * modules/ftp-method.c: (do_transfer_command), (end_transfer),
+ (ftp_connection_create), (ftp_connection_destroy):
+
2004-01-27 David Hawthorne <david hawthorne sun com>
* daemon/gnome-vfs-daemon.c
Index: libgnomevfs/gnome-vfs-socket-buffer.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-socket-buffer.c,v
retrieving revision 1.8
diff -u -r1.8 gnome-vfs-socket-buffer.c
--- libgnomevfs/gnome-vfs-socket-buffer.c 15 Jan 2004 09:55:51 -0000 1.8
+++ libgnomevfs/gnome-vfs-socket-buffer.c 30 Jan 2004 01:55:41 -0000
@@ -104,6 +104,7 @@
if (close_socket) {
gnome_vfs_socket_close (socket_buffer->socket);
+ g_free(socket_buffer->socket);
}
g_free (socket_buffer);
return GNOME_VFS_OK;
Index: modules/ftp-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/ftp-method.c,v
retrieving revision 1.96
diff -u -r1.96 ftp-method.c
--- modules/ftp-method.c 22 Jan 2004 12:29:10 -0000 1.96
+++ modules/ftp-method.c 30 Jan 2004 01:55:44 -0000
@@ -62,14 +62,12 @@
typedef struct {
GnomeVFSMethodHandle method_handle;
- GnomeVFSInetConnection *inet_connection;
GnomeVFSSocketBuffer *socket_buf;
GnomeVFSURI *uri;
gchar *cwd;
GString *response_buffer;
gchar *response_message;
gint response_code;
- GnomeVFSInetConnection *data_connection;
GnomeVFSSocketBuffer *data_socketbuf;
GnomeVFSFileOffset offset;
enum {
@@ -384,6 +382,7 @@
char *host = NULL;
gint port;
GnomeVFSResult result;
+ GnomeVFSInetConnection *data_connection;
GnomeVFSSocket *socket;
/* Image mode (binary to the uninitiated) */
@@ -414,7 +413,7 @@
}
/* connect */
- result = gnome_vfs_inet_connection_create (&conn->data_connection,
+ result = gnome_vfs_inet_connection_create (&data_connection,
host,
port,
context ? gnome_vfs_context_get_cancellation(context) : NULL);
@@ -424,16 +423,10 @@
return result;
}
- socket = gnome_vfs_inet_connection_to_socket (conn->data_connection);
+ socket = gnome_vfs_inet_connection_to_socket (data_connection);
conn->data_socketbuf = gnome_vfs_socket_buffer_new (socket);
- if (conn->socket_buf == NULL) {
- gnome_vfs_inet_connection_destroy (conn->data_connection, NULL);
- return GNOME_VFS_ERROR_GENERIC;
- }
-
- if (conn->offset)
- {
+ if (conn->offset) {
gchar *tmpstring;
tmpstring = g_strdup_printf ("REST %Lu", conn->offset);
@@ -441,8 +434,7 @@
g_free (tmpstring);
if (result != GNOME_VFS_OK) {
- gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, FALSE);
- gnome_vfs_inet_connection_destroy (conn->data_connection, NULL);
+ gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
return result;
}
}
@@ -450,16 +442,14 @@
result = do_control_write (conn, command);
if (result != GNOME_VFS_OK) {
- gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, FALSE);
- gnome_vfs_inet_connection_destroy (conn->data_connection, NULL);
+ gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
return result;
}
result = get_response (conn);
if (result != GNOME_VFS_OK) {
- gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, FALSE);
- gnome_vfs_inet_connection_destroy (conn->data_connection, NULL);
+ gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
return result;
}
@@ -501,15 +491,10 @@
if(conn->data_socketbuf) {
gnome_vfs_socket_buffer_flush (conn->data_socketbuf);
- gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, FALSE);
+ gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
conn->data_socketbuf = NULL;
}
- if (conn->data_connection) {
- gnome_vfs_inet_connection_destroy (conn->data_connection, NULL);
- conn->data_connection = NULL;
- }
-
result = get_response (conn);
return result;
@@ -545,6 +530,7 @@
gint port = control_port;
const gchar *user = anon_user;
const gchar *pass = anon_pass;
+ GnomeVFSInetConnection* inet_connection;
conn->uri = gnome_vfs_uri_dup (uri);
conn->response_buffer = g_string_new ("");
@@ -565,7 +551,7 @@
pass = gnome_vfs_uri_get_password (uri);
}
- result = gnome_vfs_inet_connection_create (&conn->inet_connection,
+ result = gnome_vfs_inet_connection_create (&inet_connection,
gnome_vfs_uri_get_host_name (uri),
port,
context ? gnome_vfs_context_get_cancellation(context) : NULL);
@@ -581,11 +567,11 @@
return result;
}
- conn->socket_buf = gnome_vfs_inet_connection_to_socket_buffer (conn->inet_connection);
+ conn->socket_buf = gnome_vfs_inet_connection_to_socket_buffer (inet_connection);
if (conn->socket_buf == NULL) {
g_warning ("Getting socket buffer failed");
- gnome_vfs_inet_connection_destroy (conn->inet_connection, NULL);
+ gnome_vfs_inet_connection_destroy (inet_connection, NULL);
gnome_vfs_uri_unref (conn->uri);
g_string_free (conn->response_buffer, TRUE);
g_free (conn);
@@ -612,8 +598,7 @@
/* login failed */
g_warning ("FTP server said: \"%d %s\"\n", conn->response_code,
conn->response_message);
- gnome_vfs_socket_buffer_destroy (conn->socket_buf, FALSE);
- gnome_vfs_inet_connection_destroy (conn->inet_connection, NULL);
+ gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE);
gnome_vfs_uri_unref (conn->uri);
g_string_free (conn->response_buffer, TRUE);
g_free (conn);
@@ -645,11 +630,8 @@
ftp_connection_destroy (FtpConnection *conn)
{
- if (conn->inet_connection)
- gnome_vfs_inet_connection_destroy (conn->inet_connection, NULL);
-
if (conn->socket_buf)
- gnome_vfs_socket_buffer_destroy (conn->socket_buf, FALSE);
+ gnome_vfs_socket_buffer_destroy (conn->socket_buf, TRUE);
gnome_vfs_uri_unref (conn->uri);
g_free (conn->cwd);
@@ -659,11 +641,8 @@
g_free (conn->response_message);
g_free (conn->server_type);
- if (conn->data_connection)
- gnome_vfs_inet_connection_destroy(conn->data_connection, NULL);
-
if (conn->data_socketbuf)
- gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, FALSE);
+ gnome_vfs_socket_buffer_destroy (conn->data_socketbuf, TRUE);
g_free (conn->dirlist);
g_free (conn->dirlistptr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]