1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
elinks/src
Kalle Olavi Niemitalo 00f5831812 Bug 1053: Fix crash when download ends prematurely.
Call stacks reported by valgrind:

==14702==    at 0x80DD791: read_from_socket (socket.c:945)
==14702==    by 0x8104D0C: read_more_http_data (http.c:1180)
==14702==    by 0x81052FE: read_http_data (http.c:1388)
==14702==    by 0x80DD69B: read_select (socket.c:910)
==14702==    by 0x80D27AA: select_loop (select.c:307)
==14702==    by 0x80D1ADE: main (main.c:358)
==14702==  Address 0x4F4E598 is 56 bytes inside a block of size 81 free'd
==14702==    at 0x402210F: free (vg_replace_malloc.c:233)
==14702==    by 0x812BED8: debug_mem_free (memdebug.c:484)
==14702==    by 0x80D7C82: done_connection (connection.c:479)
==14702==    by 0x80D8A44: abort_connection (connection.c:769)
==14702==    by 0x80D99CE: cancel_download (connection.c:1053)
==14702==    by 0x8110EB6: abort_download (download.c:143)
==14702==    by 0x81115BC: download_data_store (download.c:337)
==14702==    by 0x8111AFB: download_data (download.c:446)
==14702==    by 0x80D7B33: notify_connection_callbacks (connection.c:458)
==14702==    by 0x80D781E: set_connection_state (connection.c:388)
==14702==    by 0x80D7132: set_connection_socket_state (connection.c:234)
==14702==    by 0x80DD78D: read_from_socket (socket.c:943)

read_from_socket() attempted to read socket->fd in order to set
handlers on it, but the socket had already been freed.  Incidentally,
socket->fd was -1, which would have resulted in an assertion failure
if valgrind hadn't caught the bug first.

To fix this, add a list of weak references to sockets.
read_from_socket() registers a weak reference on entry and unregisters
it before exit.  done_socket() breaks any weak references to the
specified socket.  read_from_socket() then checks whether the weak
reference was broken, and doesn't access the socket any more if so.
2008-10-04 14:19:00 +03:00
..
bfu Strings corrections from Malcolm Parsons 2008-01-27 04:19:23 +00:00
bookmarks Declare element types of lists. 2007-07-26 22:47:23 +03:00
cache Rename cache_entry.id and related members. 2008-08-03 21:27:56 +03:00
config Display subtrees last in --config-help. 2008-03-23 19:20:12 +02:00
cookies Strings corrections from Malcolm Parsons 2008-01-27 04:19:23 +00:00
dialogs Bug 1013: Don't assume errno is between 0 and 100000 2008-08-03 17:56:41 +03:00
document Rename cache_entry.id and related members. 2008-08-03 21:27:56 +03:00
dom Fix sgml-parser so it compiles 2008-07-03 01:45:45 +02:00
ecmascript 1031: JS_SetErrorReporter only once per JSRuntime. 2008-09-07 20:17:25 +03:00
encoding Bug 1013: Don't assume errno is between 0 and 100000 2008-08-03 17:56:41 +03:00
formhist 1045: fix "void function cannot return value" in formhist 2008-09-15 23:43:52 +03:00
globhist Declare element types of lists. 2007-07-26 22:47:23 +03:00
intl const in name_to_language 2008-02-03 14:42:07 +02:00
main Hurd bug 22861: Do not select() exceptions from pipes. 2008-09-07 22:52:47 +03:00
mime Revert "Some day in the future ELinks will handle copiousoutput without external" 2008-06-15 14:39:02 +03:00
network Bug 1053: Fix crash when download ends prematurely. 2008-10-04 14:19:00 +03:00
osdep Debian bug 464384: fix OFF_T_FORMAT mismatches on amd64 2008-02-10 11:30:27 +02:00
protocol Fix blacklist crash in BitTorrent 2008-09-07 06:31:36 +03:00
scripting Let Perl scripts dynamically load libraries. 2008-09-27 21:58:08 +03:00
session Bug 1053: Fix crash when download ends. 2008-10-03 00:18:41 +03:00
terminal Bug 1053: Fix crash when download ends. 2008-10-03 00:18:41 +03:00
util mkalldirs: Reset ret when errno is EEXIST. 2008-03-29 18:41:22 +02:00
viewer Rename cache_entry.id and related members. 2008-08-03 21:27:56 +03:00
.gitignore Ignore tags file 2007-08-08 14:25:38 +02:00
elinks.h Remove now useless $Id: lines. 2005-10-21 09:14:07 +02:00
Makefile BUILD_ID: Fix dirt check when srcdir != builddir. 2008-03-01 14:30:57 +02:00
README Remove now useless $Id: lines. 2005-10-21 09:14:07 +02:00
setup.h Make copyright info independent from translations. 2007-10-03 11:53:09 +02:00
vernum.c Remove now useless $Id: lines. 2005-10-21 09:14:07 +02:00
vernum.h Remove now useless $Id: lines. 2005-10-21 09:14:07 +02:00

				  The Big View

The whole dependency tree is supposed (in ideal world) to look somewhat like
the following. Please note that this deals only with the core parts of ELinks,
not extensions like bookmarks, cookies, globhist, mime etc. Those act like
modules and are generally self-contained - the main visible difference is that
they don't have their UI stuff in dialogs/foo.c but in foo/dialogs.c.

Note also that it isn't all that clean-cut as it looks. Some parts of e.g.
lowlevel/ or osdep/ are omnipresent as well and it's meant to be so (at least
for now). Also some other exceptions are possible; the exception to this is
util/, where no exceptions are permitted - it must have no dependencies to the
rest of the code whatsoever, not even compile-time ones. The other way around,
the gettext part of intl/ is generally omnipresent but the charset part is
pretty isolated - it could be probably drawn as connected to document and
terminal (actually, it is used when encoding forms in viewer too, but that
stuff should be probably moved to document).

viewer/ contains code concerning that big rectangle between bars at the top
and bars at the bottom, documents usually being shown inside. Logically, it
is in fact kind of a BFU widget, but in practice it has little in common with
the bfu/ widgets, it is special in many ways and deeply woven to the fabric
of session/ (e.g. session history is basically a chain of viewer widget
descriptors).

dialogs/ is special too. It in fact means to say "global and unique BFU
instances belonging to the ELinks core"/ but that's a rather long and boring
name, besides the nightmares associated with maintaining files and directories
containing spaces in GIT. The "global and unique BFU instances" part can be
represented by exmode, menus and leds (were they there). The "ELinks core"
part can be represented by options, document and downloads. The reason those
aren't in their respective directories (while bookmarks or formhist have their
dialogs.c) is that it's important to keep the dependencies sorted out
reasonably. Had there been e.g. terminal/dialogs.c, it would mean libterminal
has to depend on libbfu.a and so. (There are two 'managerial' exceptions
to this; don't dig into them, please. ;-)

scripting/ (== browser scripting) is also expected to hook all around, perhaps
it should be better in the omnipresent box.

The edges are directed and represent the "using" relation. Therefore,
"bfu -> terminal" means "bfu/ is using terminal/ services (but not
the other way around)".

.---------.
| util/   | <-- This is omnipresent :)
| config/ |
| intl/   |
`---------'

                   .-------.         .---------.
                   |  bfu  |<------- | dialogs |
                   `-------' \       `---------'
                       v      `---.       |
                 .----------.      \ .--------.
                 | terminal | <----- | viewer | <-----------------.
               / `----------'     .> `--------'                   |
           .--'        v         /        v                       v
.-------. /      .----------.   |    .----------.       .----/ecmascript/----.
| osdep |<------ | lowlevel |   |    | document | ----> | document scripting |
`-------' \      `----------'   |    `----------'       `--------------------'
           `---.       ^         \        ^
                \ .---------.     `> .---------.        .----/scripting/----.
                  | network | <----- | session | -----> | browser scripting |
                  `---------'      / `---------'        `-------------------'
                       ^       .--'
                 .----------. <
                 | protocol |
                 `----------'