unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB
       [not found] <CAFNjtaA+apdrw3dhze-jSQ-Qo9j9jWpDmD=BwKCvC1DWc14=8Q@mail.gmail.com>
@ 2015-03-11 12:38 ` Anand Mohanadoss
  2016-06-23 12:22   ` Andy Wingo
  2016-06-23 13:01   ` Andy Wingo
  0 siblings, 2 replies; 4+ messages in thread
From: Anand Mohanadoss @ 2015-03-11 12:38 UTC (permalink / raw)
  To: 20079

[-- Attachment #1: Type: text/plain, Size: 2013 bytes --]

Hi,

I had sent the following to the user forum and did not receive any
comments.  I am reposting it in the bug forum with the hope that one of the
experts may be able to comment...

Thanks,
Anand

---------- Forwarded message ----------
From: Anand Mohanadoss <anand108@gmail.com>
Date: Wed, Feb 25, 2015 at 9:35 PM
Subject: Memory leak from seek/ftell with files larger than 2GB
To: guile-user@gnu.org


Hi,

We are seeing an issue with seek and ftell leaking memory with files larger
than 2GB.

We are using 2.0.11 guile built as a 32-bit application with large file
support enabled (guile was built using gcc 4.4.0 for Linux with flags
_FILE_OFFSET_BITS=64, _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE).  The
issue also appears to happen with guile 2.2.

The memory leaks start only after the offset exceeds maximum positive value
for a 32-bit signed integer. ftell and seek do work as expected (given how
lseek should work with large file support).

Appended is a program that illustrates the problem.  The first seek simply
skips the part of the file where you won't see a memory leak. If you
comment out ftell and the second seek lines and un-comment the lines that
follow them, there is no memory leak.

Is this a bug in guile or should we be doing things differently?  If this
is a known issue, is there a recommended work around?

Thanks,
Anand

(define MAX_SIGNED_INT 2147483647)
(define BYTES_TO_READ 10)

(define file "/tmp/test.pcap")  ;sample file greater than 2.5GB

(define (traverse file)
 (let* ((port (open-input-file file #:binary #t))
        (file-sz (stat:size (stat port)))
        (ua (make-bytevector BYTES_TO_READ 0))
        (cur-offset 0))
   (seek port (- MAX_UNSIGNED_INT 1000) SEEK_CUR)
   (while (< (ftell port) (- file-sz BYTES_TO_READ))
   ;(while (< cur-offset (- file-sz BYTES_TO_READ))
       (seek  port BYTES_TO_READ SEEK_CUR)
       ;(get-bytevector-n! port ua 0 BYTES_TO_READ)
       (set! cur-offset (+ BYTES_TO_READ cur-offset)))
   (close-port port)))

(traverse file)

[-- Attachment #2: Type: text/html, Size: 2757 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB
  2015-03-11 12:38 ` bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB Anand Mohanadoss
@ 2016-06-23 12:22   ` Andy Wingo
  2016-06-23 13:01   ` Andy Wingo
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2016-06-23 12:22 UTC (permalink / raw)
  To: Anand Mohanadoss; +Cc: 20079

[-- Attachment #1: Type: text/plain, Size: 55 bytes --]

Very strange bug!  I can reproduce it with this file:


[-- Attachment #2: run as "guile foo.scm" --]
[-- Type: text/plain, Size: 578 bytes --]

(use-modules (rnrs bytevectors)
             (ice-9 binary-ports))

(define MAX_SIGNED_INT 2147483647)
(define BYTES_TO_READ 10)

(define (traverse port)
  (let* ((file-sz (stat:size (stat port)))
         (ua (make-bytevector BYTES_TO_READ 0))
         (cur-offset 0))
    (let lp ((cur-offset (seek port (- MAX_SIGNED_INT 1000) SEEK_CUR)))
      (when (< cur-offset (- file-sz BYTES_TO_READ))
        (lp (seek port BYTES_TO_READ SEEK_CUR))))
    (close-port port))) 

(define port (mkstemp! (string-copy "/tmp/big-file-XXXXXX")))
(truncate-file port #e2.5e9)
(traverse port)

[-- Attachment #3: Type: text/plain, Size: 2163 bytes --]


I wonder what it could be!

Andy

On Wed 11 Mar 2015 13:38, Anand Mohanadoss <anand108@gmail.com> writes:

> Hi,
>
> I had sent the following to the user forum and did not receive any
> comments. I am reposting it in the bug forum with the hope that one of
> the experts may be able to comment...
>
> Thanks,
> Anand
>
> ---------- Forwarded message ----------
> From: Anand Mohanadoss <anand108@gmail.com>
> Date: Wed, Feb 25, 2015 at 9:35 PM
> Subject: Memory leak from seek/ftell with files larger than 2GB
> To: guile-user@gnu.org
>
> Hi,
>
> We are seeing an issue with seek and ftell leaking memory with files
> larger than 2GB.
>
> We are using 2.0.11 guile built as a 32-bit application with large
> file support enabled (guile was built using gcc 4.4.0 for Linux with
> flags _FILE_OFFSET_BITS=64, _LARGEFILE_SOURCE and _
> LARGEFILE64_SOURCE). The issue also appears to happen with guile 2.2.
>
> The memory leaks start only after the offset exceeds maximum positive
> value for a 32-bit signed integer. ftell and seek do work as expected
> (given how lseek should work with large file support).
>
> Appended is a program that illustrates the problem. The first seek
> simply skips the part of the file where you won't see a memory leak.
> If you comment out ftell and the second seek lines and un-comment the
> lines that follow them, there is no memory leak. 
>
> Is this a bug in guile or should we be doing things differently? If
> this is a known issue, is there a recommended work around?
>
> Thanks,
> Anand
>
> (define MAX_SIGNED_INT 2147483647)
> (define BYTES_TO_READ 10)
>
> (define file "/tmp/test.pcap") ;sample file greater than 2.5GB
>
> (define (traverse file)
> (let* ((port (open-input-file file #:binary #t))
> (file-sz (stat:size (stat port)))
> (ua (make-bytevector BYTES_TO_READ 0))
> (cur-offset 0))
> (seek port (- MAX_UNSIGNED_INT 1000) SEEK_CUR)
> (while (< (ftell port) (- file-sz BYTES_TO_READ))
> ;(while (< cur-offset (- file-sz BYTES_TO_READ))
> (seek port BYTES_TO_READ SEEK_CUR)
> ;(get-bytevector-n! port ua 0 BYTES_TO_READ)
> (set! cur-offset (+ BYTES_TO_READ cur-offset)))
> (close-port port))) 
>
> (traverse file)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB
  2015-03-11 12:38 ` bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB Anand Mohanadoss
  2016-06-23 12:22   ` Andy Wingo
@ 2016-06-23 13:01   ` Andy Wingo
  2016-06-23 14:43     ` Anand Mohanadoss
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2016-06-23 13:01 UTC (permalink / raw)
  To: Anand Mohanadoss; +Cc: 20079-done

Hi,

Thank you very much for this one!  Turns out we had an incredibly
embarrassing bug in which we forgot to attach finalizers for bignums
created by scm_from_{uint64,int64} on 32-bit platforms.  Fixed in master
and stable-2.0.

Cheers,

Andy

On Wed 11 Mar 2015 13:38, Anand Mohanadoss <anand108@gmail.com> writes:

> Hi,
>
> I had sent the following to the user forum and did not receive any
> comments. I am reposting it in the bug forum with the hope that one of
> the experts may be able to comment...
>
> Thanks,
> Anand
>
> ---------- Forwarded message ----------
> From: Anand Mohanadoss <anand108@gmail.com>
> Date: Wed, Feb 25, 2015 at 9:35 PM
> Subject: Memory leak from seek/ftell with files larger than 2GB
> To: guile-user@gnu.org
>
> Hi,
>
> We are seeing an issue with seek and ftell leaking memory with files
> larger than 2GB.
>
> We are using 2.0.11 guile built as a 32-bit application with large
> file support enabled (guile was built using gcc 4.4.0 for Linux with
> flags _FILE_OFFSET_BITS=64, _LARGEFILE_SOURCE and _
> LARGEFILE64_SOURCE). The issue also appears to happen with guile 2.2.
>
> The memory leaks start only after the offset exceeds maximum positive
> value for a 32-bit signed integer. ftell and seek do work as expected
> (given how lseek should work with large file support).
>
> Appended is a program that illustrates the problem. The first seek
> simply skips the part of the file where you won't see a memory leak.
> If you comment out ftell and the second seek lines and un-comment the
> lines that follow them, there is no memory leak. 
>
> Is this a bug in guile or should we be doing things differently? If
> this is a known issue, is there a recommended work around?
>
> Thanks,
> Anand
>
> (define MAX_SIGNED_INT 2147483647)
> (define BYTES_TO_READ 10)
>
> (define file "/tmp/test.pcap") ;sample file greater than 2.5GB
>
> (define (traverse file)
> (let* ((port (open-input-file file #:binary #t))
> (file-sz (stat:size (stat port)))
> (ua (make-bytevector BYTES_TO_READ 0))
> (cur-offset 0))
> (seek port (- MAX_UNSIGNED_INT 1000) SEEK_CUR)
> (while (< (ftell port) (- file-sz BYTES_TO_READ))
> ;(while (< cur-offset (- file-sz BYTES_TO_READ))
> (seek port BYTES_TO_READ SEEK_CUR)
> ;(get-bytevector-n! port ua 0 BYTES_TO_READ)
> (set! cur-offset (+ BYTES_TO_READ cur-offset)))
> (close-port port))) 
>
> (traverse file)





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB
  2016-06-23 13:01   ` Andy Wingo
@ 2016-06-23 14:43     ` Anand Mohanadoss
  0 siblings, 0 replies; 4+ messages in thread
From: Anand Mohanadoss @ 2016-06-23 14:43 UTC (permalink / raw)
  To: Andy Wingo; +Cc: 20079-done

[-- Attachment #1: Type: text/plain, Size: 2626 bytes --]

Hi Andy,

Thanks a lot for the fix!

Anand

On Thu, Jun 23, 2016 at 6:31 PM, Andy Wingo <wingo@pobox.com> wrote:

> Hi,
>
> Thank you very much for this one!  Turns out we had an incredibly
> embarrassing bug in which we forgot to attach finalizers for bignums
> created by scm_from_{uint64,int64} on 32-bit platforms.  Fixed in master
> and stable-2.0.
>
> Cheers,
>
> Andy
>
> On Wed 11 Mar 2015 13:38, Anand Mohanadoss <anand108@gmail.com> writes:
>
> > Hi,
> >
> > I had sent the following to the user forum and did not receive any
> > comments. I am reposting it in the bug forum with the hope that one of
> > the experts may be able to comment...
> >
> > Thanks,
> > Anand
> >
> > ---------- Forwarded message ----------
> > From: Anand Mohanadoss <anand108@gmail.com>
> > Date: Wed, Feb 25, 2015 at 9:35 PM
> > Subject: Memory leak from seek/ftell with files larger than 2GB
> > To: guile-user@gnu.org
> >
> > Hi,
> >
> > We are seeing an issue with seek and ftell leaking memory with files
> > larger than 2GB.
> >
> > We are using 2.0.11 guile built as a 32-bit application with large
> > file support enabled (guile was built using gcc 4.4.0 for Linux with
> > flags _FILE_OFFSET_BITS=64, _LARGEFILE_SOURCE and _
> > LARGEFILE64_SOURCE). The issue also appears to happen with guile 2.2.
> >
> > The memory leaks start only after the offset exceeds maximum positive
> > value for a 32-bit signed integer. ftell and seek do work as expected
> > (given how lseek should work with large file support).
> >
> > Appended is a program that illustrates the problem. The first seek
> > simply skips the part of the file where you won't see a memory leak.
> > If you comment out ftell and the second seek lines and un-comment the
> > lines that follow them, there is no memory leak.
> >
> > Is this a bug in guile or should we be doing things differently? If
> > this is a known issue, is there a recommended work around?
> >
> > Thanks,
> > Anand
> >
> > (define MAX_SIGNED_INT 2147483647)
> > (define BYTES_TO_READ 10)
> >
> > (define file "/tmp/test.pcap") ;sample file greater than 2.5GB
> >
> > (define (traverse file)
> > (let* ((port (open-input-file file #:binary #t))
> > (file-sz (stat:size (stat port)))
> > (ua (make-bytevector BYTES_TO_READ 0))
> > (cur-offset 0))
> > (seek port (- MAX_UNSIGNED_INT 1000) SEEK_CUR)
> > (while (< (ftell port) (- file-sz BYTES_TO_READ))
> > ;(while (< cur-offset (- file-sz BYTES_TO_READ))
> > (seek port BYTES_TO_READ SEEK_CUR)
> > ;(get-bytevector-n! port ua 0 BYTES_TO_READ)
> > (set! cur-offset (+ BYTES_TO_READ cur-offset)))
> > (close-port port)))
> >
> > (traverse file)
>

[-- Attachment #2: Type: text/html, Size: 3505 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-23 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAFNjtaA+apdrw3dhze-jSQ-Qo9j9jWpDmD=BwKCvC1DWc14=8Q@mail.gmail.com>
2015-03-11 12:38 ` bug#20079: Fwd: Memory leak from seek/ftell with files larger than 2GB Anand Mohanadoss
2016-06-23 12:22   ` Andy Wingo
2016-06-23 13:01   ` Andy Wingo
2016-06-23 14:43     ` Anand Mohanadoss

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 read-only IMAP folder(s) and NNTP newsgroup(s).