Thread: A memory leak

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    23
    Everyone, do I need to correct the program because splint printed these messages?

    plicitly temp storage numbers returned as implicitly only:
    numbers
    Temp storage (associated with a formal parameter) is transferred to a
    non-temporary reference. The storage may be released or new aliases created.
    (Use -temptrans to inhibit warning)
    fibo.c: (in function main)
    fibo.c:48:38: Passed storage numbers not completely defined (*numbers is
    undefined): fibonacci_numbers (numbers, ...)
    Storage derivable from a parameter, return value or global is not defined.
    Use /*@out@*/ to denote passed or returned storage which need not be defined.
    (Use -compdef to inhibit warning)
    fibo.c:48:20: New fresh storage (type unsigned int *) passed as implicitly temp
    (not released): fibonacci_numbers(numbers, count)
    A memory leak has been detected. Storage allocated locally is not released
    before the last reference to it is lost. (Use -mustfreefresh to inhibit
    warning)


    Finished checking --- 3 code warningsibo.c:32:9: Implicitly temp storage numbers returned as implicitly only:
    numbers
    Temp storage (associated with a formal parameter) is transferred to a
    non-temporary reference. The storage may be released or new aliases created.
    (Use -temptrans to inhibit warning)
    fibo.c: (in function main)
    fibo.c:48:38: Passed storage numbers not completely defined (*numbers is
    undefined): fibonacci_numbers (numbers, ...)
    Storage derivable from a parameter, return value or global is not defined.
    Use /*@out@*/ to denote passed or returned storage which need not be defined.
    (Use -compdef to inhibit warning)
    fibo.c:48:20: New fresh storage (type unsigned int *) passed as implicitly temp
    (not released): fibonacci_numbers(numbers, count)
    A memory leak has been detected. Storage allocated locally is not released
    before the last reference to it is lost. (Use -mustfreefresh to inhibit
    warning)


    Finished checking --- 3 code warnings

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    BillMcEnaney:

    Everyone, do I need to correct the program because splint printed these messages?
    IMHO, No.

    splint is outdated and has too many "False Positives". Apparently it has not been updated since 2007, prior to the C11 and C17 C Standards were published!

    [splint 2007-07-12 (3.1.2)]

    I would dump splint!

    Please look a the list of static Code checkers on Wikipedia, and try several of the ones compatible with MacOS, you seem to be using.

    Your code is correct as written, with one exception, although there are more than one way to code Fibonacci numbers.

    Please look at my suggestions in my previous post #2, especially checking the return value from scanf() to check for bad input! This one is very important!

    You will need a loop to check for errors, remove the garbage from the input buffer, but NOT with fflush(), then ask the user to input a new entry till legitimate input has been entered.
    Last edited by rstanley; 03-25-2024 at 07:17 AM.

  3. #3
    Registered User
    Join Date
    May 2020
    Posts
    23
    Thank you for the excellent tips, rstanley. I'll do what you suggest. Meanwhile, please suggest a program to replace splint because I don't think anyone ported lint to MacOS. That OS doesn't even come with yacc and bison. Then again, I'll think I'm cheating to use a parser generator when I write a compiler.

    Naturally, I know that sane programmers don't want to reinvent the wheel. So I realize that a parser generator would save me plenty of work and even a headache or two. But I want to learn how to write elegant code on my own. If you've read any programs a from a parser generator, you know it won't make you exclaim, "Wow, that's gorgeous."

    You should have seen the lousy Cobol programs I maintained years ago. I still hate the wordy language. When I program, I want my code's meaning to be clear to anyone who knows the language I wrote it in. But that goal is hard to reach when you need about 20 lines to write a "Hello, world" program.

    Though I don't mean to brag, in my Cobol days, only I knew how to find a square root in Cobol. Or so it seemed. Another programmer earned a B.S. degree in mathematics before his programming carer. Nobody there thought, "Aha, I'll raise a number to the half power."

    I drove home, translated a Pascal function into Cobol, and handed the Cobol code to them mathematician who thought it contained in infinite loop. But another guy added my code the program that needed it. That code worked correctly the first time and forever after that. Maybe that convinced the other programmers that it was good for me to keep my head in the academic clouds, though I risked getting my nose sideswiped by a Boeing 767.

    Then again, it disappointed me to know the square root "function" was the only original code I put into production back then. I longed for a day when my boss would let me write a program from scratch because my AI professor said I wrote "damn good code." That boss handed me a specification for a new program before we discovered that his boss decided to lay me off. Yes, I do mean "layoff." It's not a euphemism for getting fired. A few mons later, the company went out of business.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,127
    Quote Originally Posted by BillMcEnaney View Post
    Call me old-fashioned because I always want to write fully portable code without dialect-specific features.
    You are not being "Old Fashioned"! Just stick to using the Standard C Library and your code will be very portable. Avoid most, if not all of the compiler specific extension functions!

    Quote Originally Posted by BillMcEnaney View Post
    C is for programmers much more skillful than I'll ever be.
    C is for anyone who will take the time to thoroughly learn the language, understand it's pitfalls, and how to avoid them! You don't have to become an "expert" to use and appreciate the language!

    If you read my previous reply, you know that cppcheck is available for MacOS. Look at the Cppcheck web page, and you will see that the command presented, "brew install cppcheck" should install it on you Mac.

    I don't use Mac so you are on your own if the command you need is different than the one presented.

    As for other possible Static Code Analyzers for MacOS, a simple Google search command will present many sites you can explore for other analyzers. I can't do all the work for you!

    Good luck!
    Last edited by rstanley; 03-27-2024 at 05:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By *nick in forum Windows Programming
    Replies: 8
    Last Post: 09-17-2012, 06:15 PM
  2. Possible memory leak?
    By 127.0.0.1 in forum C Programming
    Replies: 21
    Last Post: 05-02-2011, 04:53 PM
  3. Replies: 2
    Last Post: 09-28-2006, 01:06 PM
  4. Is this a memory leak?
    By jasonhv in forum C++ Programming
    Replies: 5
    Last Post: 10-20-2005, 08:37 PM
  5. How is this a Memory Leak?
    By Cheeze-It in forum C++ Programming
    Replies: 4
    Last Post: 05-24-2002, 04:59 AM

Tags for this Thread