caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jørgen Hermanrud Fjeld" <jhf@hex.no>
To: caml-list@inria.fr
Subject: Segfault with close_out in ocaml 3.09.2
Date: Sun, 1 Jul 2007 20:41:17 +0200	[thread overview]
Message-ID: <20070701184116.GA25644@hex.no> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1124 bytes --]

Hi!
I can provoke a segfault with close_out, and suspect a bug somewhere in
ocaml 3.09.2 or the Pervasives module of ocaml 3.09.2, as shipping with 
Ubuntu feisty.

To reproduce, save the attached files, use ocaml 3.09.2 and run
####
ocamlopt unix.cmxa -o nosegfault nosegfault.ml
ocamlopt unix.cmxa -o segfault segfault.ml
./nosegfault ; ./segfault
####

The difference between segfault.ml and nosegfault.ml is the allocation 
of a large string
####
let _ = String.create (Sys.max_string_length) in
####

The bug appears for the second call to close_out.

When I use Unix.close, there is no problem.

The original code where the testcase is derived form ran fine when
compiled with ocaml 3.08.

When I use ocaml 3.10.0 the problem is gone.

If someone can help discover why the segfault appears that would be
nice.
Since the bug disappears in ocaml 3.10, the bug is probably fixed, 
which one can check when the cause of the segfault is discovered.


-- 
Sincerely | Homepage:
Jørgen    | http://www.hex.no/jhf
          | Public GPG key:
          | http://www.hex.no/jhf/key.txt



[-- Attachment #1.2: segfault.ml --]
[-- Type: text/plain, Size: 695 bytes --]

let run closer command = 
  let (from_command,to_command) = Unix.open_process command in
    closer to_command ;
    try while true do 
          print_endline (input_line from_command) ;
        done
    with End_of_file -> () ;
    ignore (Unix.close_process (from_command,to_command)) ;;

let _ = String.create (Sys.max_string_length) in
run (fun to_command -> Unix.close (Unix.descr_of_out_channel to_command)) "echo 1" ;
run (fun to_command -> Unix.close (Unix.descr_of_out_channel to_command)) "echo 2" ;
run (fun to_command -> close_out to_command)                              "echo 3" ;
run (fun to_command -> close_out to_command)                              "echo 4" ;

[-- Attachment #1.3: nosegfault.ml --]
[-- Type: text/plain, Size: 645 bytes --]

let run closer command = 
  let (from_command,to_command) = Unix.open_process command in
    closer to_command ;
    try while true do 
          print_endline (input_line from_command) ;
        done
    with End_of_file -> () ;
    ignore (Unix.close_process (from_command,to_command)) ;;

run (fun to_command -> Unix.close (Unix.descr_of_out_channel to_command)) "echo 1" ;
run (fun to_command -> Unix.close (Unix.descr_of_out_channel to_command)) "echo 2" ;
run (fun to_command -> close_out to_command)                              "echo 3" ;
run (fun to_command -> close_out to_command)                              "echo 4" ;

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2007-07-01 18:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01 18:41 Jørgen Hermanrud Fjeld [this message]
2007-07-02 13:25 ` [Caml-list] " Martin Jambon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070701184116.GA25644@hex.no \
    --to=jhf@hex.no \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).