help finding a memory leak

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

help finding a memory leak

Wilfried-5
Hello all,

I contribute to the latex2rtf converter project by compiling and
packaging the DOS / Windows port. I have good experiences in Fortran
programming but only few in C/C++, and even less in using a debugger, so
I ask here whether someone could help.

The program is written in C with command line interface and mainly works
as intended under Mac OSX, Linux, cygwin and Windows (djgpp or MinGW
compiler).

There only is a problem when a lot of equations are to be converted to
bitmaps (-M12 option) with the windows version (compiled with MinGW
under MSYS). Under MacOSX the problem does NOT occur, so the main
latex2rtf developer (who works on MacOSX) can not locate the problem.
The executable made with the djgpp compiler has a similar problem but
that seems to be caused by djgpp only allowing a certain number of calls
to system(), so let us here concentrate on the MinGW version.

The conversion process is as follows:
- latex2rt.exe writes a LaTeX snippet to a disk file
- latex2rt.exe issues a SYSTEM call which starts bash
   (from http://sourceforge.net/projects/win-bash/ )
- - which runs the shell script latex2png
- - which
- - - runs some shell utilities from
       http://sourceforge.net/projects/gnuwin32/
- - - calls LaTeX (MikTeX) to convert .tex to .dvi
- - - calls dvips (MikTeX) to convert .dvi to .eps
- - - calls convert (ImageMagick Windows version)
       to convert .eps to .png
- - - calls convert to crop the .png
- - - calls convert to extract the first column of the bitmap
       to a .pbm file to determine the baseline
- latex2rt.exe reads the .png and .pbm files and includes the .png in
the rtf output.

latex2rtf converts a number of equations to bitmaps, then stops, or
freezes with 100% CPU. The number of eqns converted is about 100 to 300,
depending whether running under Vista (less) or XP (more), and whether
run from the GUI shell (less) or the command prompt (more).

To locate the problem,

a) I wrote a small c program so that only a (constant) input file for
the script is written and the script is called. This runs
successfully for at least 500 equations. So it is neither the script
nor the programs called by the script.

b) I modified latex2rtf so that no system call is issued and
therefore the script is not run. The error still occurs. So it must
be a bug in the latex2rtf code (e.g. failing to close a file) but I
can not find any, and the bug does not occur on Mac OSX.

c) After a test run of latex2rtf, I edited a file and wanted it to save.
The editor issued the error message "File can not be saved. Unable to
allocate memory for file access control block".
The problem goes away when the command prompt window in which latex2rtf
was run is closed.
So I suspect it may be a memory leak or a problem of not correctly
freeing the file access blocks. Maybe it's a coding error in latex2rtf,
but it could also be a bug in MinGW.

Anyone interested to help can download the Windows port (including
installer) and the source from
http://sourceforge.net/projects/latex2rtf/
latex2rtf-win package, version 1.9.20, pre-release.
Extract the file ttgfsr7.tex from the "test" folder in the source
code zip file, run it through LaTeX (to generate the .aux file needed by
latex2rtf) and then through "latex2rt -M12 ttgfsr7". This is the only
file in the test suite which has enough equations to reveal the problem.

Thanks for any help.


--
Wilfried Hennings
whiskey hotel underscore november golf at golf mike xray dot delta echo


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: help finding a memory leak

Nathan Schulte-2
On Mon, Nov 23, 2009 at 9:16 AM, Wilfried <[hidden email]> wrote:
> So I suspect it may be a memory leak or a problem of not correctly
> freeing the file access blocks. Maybe it's a coding error in latex2rtf,
> but it could also be a bug in MinGW.

I remember playing with
http://www.flipcode.com/archives/Presenting_A_Memory_Manager.shtml,
perhaps that will help?

> Thanks for any help.

Sorry I can't be of any actual help, perhaps someone who is able to
help will find the above beneficial.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: help finding a memory leak

Tuomo Latto
In reply to this post by Wilfried-5
Wilfried wrote:
> c) After a test run of latex2rtf, I edited a file and wanted it to save.
> The editor issued the error message "File can not be saved. Unable to
> allocate memory for file access control block".
> The problem goes away when the command prompt window in which latex2rtf
> was run is closed.
> So I suspect it may be a memory leak or a problem of not correctly
> freeing the file access blocks. Maybe it's a coding error in latex2rtf,
> but it could also be a bug in MinGW.

I would try to track down the error message to see where it is generated
or, to be more exact, try to track down the possible points of failure.
Have you used Task manager etc. to see if you are actually running out
of memory (and if there are suspiciously large numbers in other columns)?

Knowing nothing about latex2rtf, I find the error message cryptic enough
to likewise suspect that you might be running out of handles or leaking
something on the "kernel side" of things. That might also explain why you
are hitting the limit with DJGPP (DOS) as well.
I think unix-like systems generally have higher limits in all kernel
structures, which might explain why the problem doesn't manifest itself
there.

I hope you find out the cause.


--
Tuomo

... Beware of programmers carrying screwdrivers


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: help finding a memory leak

Vincent Torri


On Tue, 24 Nov 2009, Tuomo Latto wrote:

> Wilfried wrote:
>> c) After a test run of latex2rtf, I edited a file and wanted it to save.
>> The editor issued the error message "File can not be saved. Unable to
>> allocate memory for file access control block".
>> The problem goes away when the command prompt window in which latex2rtf
>> was run is closed.
>> So I suspect it may be a memory leak or a problem of not correctly
>> freeing the file access blocks. Maybe it's a coding error in latex2rtf,
>> but it could also be a bug in MinGW.
>
> I would try to track down the error message to see where it is generated
> or, to be more exact, try to track down the possible points of failure.
> Have you used Task manager etc. to see if you are actually running out
> of memory (and if there are suspiciously large numbers in other columns)?
>
> Knowing nothing about latex2rtf, I find the error message cryptic enough
> to likewise suspect that you might be running out of handles or leaking
> something on the "kernel side" of things. That might also explain why you
> are hitting the limit with DJGPP (DOS) as well.
> I think unix-like systems generally have higher limits in all kernel
> structures, which might explain why the problem doesn't manifest itself
> there.

using mpatrol ?

Vincent Torri

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: help finding a memory leak

Wilfried-5
In reply to this post by Nathan Schulte-2
Nathan Schulte <[hidden email]> wrote:

> On Mon, Nov 23, 2009 at 9:16 AM, Wilfried <[hidden email]> wrote:
> > So I suspect it may be a memory leak or a problem of not correctly
> > freeing the file access blocks. Maybe it's a coding error in latex2rtf,
> > but it could also be a bug in MinGW.
>
> I remember playing with
> http://www.flipcode.com/archives/Presenting_A_Memory_Manager.shtml,
> perhaps that will help?

Thanks for pointing to this.
We meanwhile found some leaks (with a different debugging aid) but there
is still a problem under Vista. I started a new thread for this.

Just for the records: The Memory Manager is no longer available for
download from flipcode, but instead from the author's site
http://www.paulnettle.com/

As the package is C++, it was tricky to include it in our source code
which is plain C. I finally switched from gcc to c++ which fortunately
also compiles our plain C code (with a few changes).

--
Wilfried Hennings


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users