From: Lodewijk Voge <lodewijk@reddwarf.xs4all.nl>
To: caml-list@inria.fr
Subject: memory leak in C snippet?
Date: Tue, 28 Dec 2004 20:32:14 +0100 [thread overview]
Message-ID: <2D67CB0C-5907-11D9-B386-000A95A068A6@reddwarf.xs4all.nl> (raw)
hello,
I'm writing a daemon in ocaml with some glue code in C. it all works
fine, except memory seems to leak to a point the daemon can last
only about a week on the smallest systems. after a lot of removing code
I come to this snippet that seems to leak:
external bar: unit -> Unix.inet_addr * unit = "bar"
let _ =
let s = String.create 392 in
while true do
ignore(bar ());
done
with
CAMLprim value bar(value unit) {
CAMLparam1(unit);
CAMLlocal2(res, addr);
int i;
addr = alloc_string(4);
*(int *)(String_val(addr)) = htonl(0xac100000);
res = alloc_tuple(2);
Store_field(res, 0, addr);
Store_field(res, 1, Val_unit);
CAMLreturn(res);
}
which gives when run:
~/test$ while /usr/bin/true; do ps -o rss -p 15696 | tail -1; sleep 2;
done
784
784
788
792
796
800
804
808
812
^C
an ever growing RSS. strangely, having bar() return just the alloced
string instead of a tuple, this doesn't occur. even more strangely, if
I delete the let s = String.make 392 line, it doesn't occur either.
systems tested are MacOS X, FreeBSD (the target system) and Linux. as
the RSS approaches the segment size that'll expand too, and this
gobbles up all available virtual memory in a week on the smallest
target systems.
so, my question is: can anyone see an obvious error in the C snippet?
some violation of the rules in the manual I missed?
thanks,
Lodewijk
next reply other threads:[~2004-12-28 19:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-28 19:32 Lodewijk Voge [this message]
2004-12-31 9:35 ` [Caml-list] " Matthieu Brucher
2004-12-31 11:14 ` Lodewijk Voge
2004-12-31 15:10 ` Jon Harrop
2004-12-31 15:48 ` Lodewijk Voge
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=2D67CB0C-5907-11D9-B386-000A95A068A6@reddwarf.xs4all.nl \
--to=lodewijk@reddwarf.xs4all.nl \
--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