Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Lwt_unix.files_of_directory #229

Closed
samoht opened this issue Apr 4, 2016 · 2 comments
Closed

Memory leak in Lwt_unix.files_of_directory #229

samoht opened this issue Apr 4, 2016 · 2 comments

Comments

@samoht
Copy link

samoht commented Apr 4, 2016

The following simple program shows how to reproduce:

(* test.ml *)
open Lwt.Infix

let list_files dir =
  let s = Lwt_unix.files_of_directory dir in
  let s = Lwt_stream.filter (fun s -> s <> "." && s <> "..") s in
  let s = Lwt_stream.map (Filename.concat dir) s in
  Lwt_stream.to_list s

let rec loop () =
  Gc.full_major ();
  list_files "." >>= fun _l ->
  loop ()

let () = Lwt_main.run (loop ())

To compile:

$ ocamlfind ocamlopt -package lwt.unix test.ml -linkpkg -o test

Then look at how fast the memory consumption grow.

@samoht
Copy link
Author

samoht commented Apr 4, 2016

Actually @talex5 has an even shorter repro-case:

open Lwt

let rec loop () =
  Lwt_unix.opendir "/" >>= fun handle ->
  Lwt_unix.readdir_n handle 1024 >>= fun entries ->
  Lwt_unix.closedir handle >>= fun () ->
  ignore entries;
  loop ()

let () =
  Lwt_main.run (loop ())

@talex5
Copy link
Contributor

talex5 commented Apr 4, 2016

I guess it's missing a call to lwt_unix_free_job in the success branch here:

static value result_readdir_n(struct job_readdir_n *job)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants