[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

VStudio 6 Fortran calling C functions memory leak

I have a legacy app written in Compaq Fortran which calls C functions within the Visual Studio 6 IDE. I have determined that there is a memory leak that occurs due to something in the calling of C functions from Fortran code....

I am assuming this has somethihng to do with garbage collection or lack thereof once the functio n returns. I realize this is a difficult/ambiguous question but anyone know how I can fix the leak? I set break point before sand after the call and see that memory usage (via Task Manager) goes up each time.

0
smmsmm57
Asked:
smmsmm57
  • 3
  • 2
  • 2
2 Solutions
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi smmsmm57,

Every function in C has the potential to allocate memory that is never freed.  Look for calls to alloc(), calloc(), malloc(), strdup(), fopen(), freopen(), etc.  (There are quite a few C functions that allocate memory.)

Can you post the C code?  I'll be glad to check it out.


Kent
0
 
smmsmm57Author Commented:
I apologize, I left out a crucial detail, I only have the dll and not the source of the c functions since it is a proprietary function.....

IN the past I have written to authours of it to see if they have any malloc, etc in code and they said they do not, I can only take their word for it....
0
 
AndyAinscowCommented:
If the leak is in the dll and you don't have the source code then - not much you can do apart from put up with it.

How serious is the leak ?  Bytes or tens of MBs ?
What happens if you unload the library then load it again - does the memory get released?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
smmsmm57Author Commented:
As far as I know I dont have ability to load/unload library, assume that is done automatically for me, if I understand what you are asking me....I understand difficulty of trying to figure out w/o source code though...
0
 
AndyAinscowCommented:
My Fortran is years old - do you have anything like LoadLibrary("name of dll goes here") in the fortran code?
0
 
smmsmm57Author Commented:
no....my Fortran is years old also
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi smmsmm57,

Fortran and C aren't generally compatible as most Fortran implementations are not stack based while C implementations are.  That means that before the C function is called, a stack must be set up and initialized and all of the proper stack and register values set up to make the stack usable.

The DLL undoubtedly does this.  So if you're seeing what appears to be a memory leak, it may be that you're calling the initialization code in the DLL more than once.  That would generate redundant stacks that could well appear as a memory leak.

And it could be that the DLL is doing that without you knowing about it.

Check your loading of the DLL and calls to it.  Make sure that you aren't calling the initialization code more than once.  Beyond that, there's probably not a lot that you can do to fix the leak.


Good Luck,
Kent
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now