File descriptor leak patch for Evolution
Jules Colding <[email protected]> Mon, 28 May 2007 17:04:36 +0200
| Newsgroups | gmane.comp.gnome.evolution.patches |
|---|---|
| Message-ID | <[email protected]> |
Hi, The patch below will fix the very few file descriptor leaks that I've found in Evolution. I've reviewed the source for leaks from open() and opendir(). Only a few was found. May I commit? Best regards and thanks, jules Index: shell/ChangeLog =================================================================== --- shell/ChangeLog (revision 33593) +++ shell/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2007-05-28 Jules Colding <[email protected]> + + * main.c (main): Prevent dup2() and close() on -1 + 2007-05-13 Matthew Barnes <[email protected]> * e-shell.c (impl_Shell_handleURI): Index: shell/main.c =================================================================== --- shell/main.c (revision 33593) +++ shell/main.c (working copy) @@ -541,7 +541,7 @@ int fd; fd = g_open (evolution_debug_log, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (fd) { + if (fd != -1) { dup2 (fd, STDOUT_FILENO); dup2 (fd, STDERR_FILENO); close (fd); Index: mail/ChangeLog =================================================================== --- mail/ChangeLog (revision 33593) +++ mail/ChangeLog (working copy) @@ -1,3 +1,17 @@ +2007-05-28 Jules Colding <[email protected]> + + * em-utils.c (em_utils_selection_set_urilist): Fix file leak + (em_utils_selection_get_urilist): Fix file leak + + * importers/evolution-outlook-importer.c (import_outlook_import): Fix file leak + +2007-05-25 Jules Colding <[email protected]> + + * importers/mail-importer.c (import_mbox_import): Impossible code branch commented + + * importers/netscape-importer.c (netscape_import_filters): Fix file leak + (netscape_init_prefs): Fix file leak + 2007-05-25 Matthew Barnes <[email protected]> * mail-send-recv.c: Index: mail/em-utils.c =================================================================== --- mail/em-utils.c (revision 33593) +++ mail/em-utils.c (working copy) @@ -1115,7 +1115,9 @@ } camel_object_unref(fstream); - } + } else + close(fd); + g_free(uri); } @@ -1154,8 +1156,11 @@ if (strcmp(url->protocol, "file") == 0 && (fd = g_open(url->path, O_RDONLY | O_BINARY, 0)) != -1) { stream = camel_stream_fs_new_with_fd(fd); - res = em_utils_read_messages_from_stream(folder, stream); - camel_object_unref(stream); + if (stream) { + res = em_utils_read_messages_from_stream(folder, stream); + camel_object_unref(stream); + } else + close(fd); } camel_url_free(url); } Index: mail/importers/mail-importer.c =================================================================== --- mail/importers/mail-importer.c (revision 33593) +++ mail/importers/mail-importer.c (working copy) @@ -223,7 +223,7 @@ mp = camel_mime_parser_new(); camel_mime_parser_scan_from(mp, TRUE); - if (camel_mime_parser_init_with_fd(mp, fd) == -1) { + if (camel_mime_parser_init_with_fd(mp, fd) == -1) { /* will never happen - 0 is unconditionally returned */ goto fail2; } Index: mail/importers/netscape-importer.c =================================================================== --- mail/importers/netscape-importer.c (revision 33593) +++ mail/importers/netscape-importer.c (working copy) @@ -1238,7 +1238,7 @@ exit: g_free(user); g_object_unref((fc)); - + fclose (mailrule_handle); } /* Email folder & accounts stuff ----------------------------------------------- */ @@ -1444,6 +1444,7 @@ g_hash_table_insert (user_prefs, key, value); } + fclose (prefs_handle); return; } Index: mail/importers/evolution-outlook-importer.c =================================================================== --- mail/importers/evolution-outlook-importer.c (revision 33593) +++ mail/importers/evolution-outlook-importer.c (working copy) @@ -316,6 +316,7 @@ struct _import_outlook_msg *m = (struct _import_outlook_msg *) mm; struct stat st; CamelFolder *folder; + int fd = -1; if (stat(m->path, &st) == -1) { g_warning("cannot find source file to import '%s': %s", m->path, g_strerror(errno)); @@ -334,7 +335,6 @@ CamelOperation *oldcancel = NULL; CamelMessageInfo *info; GByteArray *buffer; - int fd; off_t pos; fd = g_open(m->path, O_RDONLY|O_BINARY, 0); @@ -413,6 +413,8 @@ g_byte_array_free(buffer, TRUE); } fail: + if (fd != -1) + close(fd); camel_object_unref(folder); }