简体   繁体   中英

Memory leak in 32 bit CPU processor and no leak in 64 bit processor CPU

I have a C code that runs without any memory leak in 64 bit CPU processor but shows leak in 32 bit processor. What can be the reason for it. GCC 4.1.2 is the compiler and Debian is the operating system.

That sounds weird. But it's too vague to answer, for me. Since you're on Linux though, I would recommend that you simply run the 32-bit version under Valgrind , with maximum memory tracking.

Keep in mind that even though your own code is the same, you are still running two distinct programs -- there are different runtime libraries they are linked against. It could be that some aspect of your code is triggering a leak in one runtime and not another. If that is the case, it can occur in one of two ways:

a) You've done nothing badly. The problem is in the 32-bit runtime.

or

b) You have something wrong, but something defensive in the 64-bit runtime is masking it.

Really hard to tell without the code. Things that can go wrong

  • implicit conversions. in most places narrow data types are converted to signed or unsigned . If you have implicit assumptions on the width of of these, you may have all kind of things: overflow, undefined behavior, compiler specific behavior
  • missing function prototypes. oldish C assumes that a function that it doesn't know return an int . If in reality it returns a pointer (eg) you are in trouble.
  • pointer to int conversions (or the other way round)

Your compiler is quite old. You probably should try do obtain something more recent, if possible, or try something different like clang .

Compile with all warnings on -Wall -Wextra ... and work on your code until it doesn't have any warning at all.

If your problem persists run it with valgrind as @unwind suggested.

Then with a concrete problem some back here, so we might help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM