Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:47:26+00:00 2026-05-26T04:47:26+00:00

==20420== ==20420== HEAP SUMMARY: ==20420== in use at exit: 0 bytes in 1 blocks

  • 0
==20420== 
==20420== HEAP SUMMARY:
==20420==     in use at exit: 0 bytes in 1 blocks
==20420==   total heap usage: 1 allocs, 0 frees, 0 bytes allocated
==20420== 
==20420== Searching for pointers to 1 not-freed blocks
==20420== Checked 48,492 bytes
==20420== 
==20420== 0 bytes in 1 blocks are still reachable in loss record 1 of 1
==20420==    at 0x400677E: malloc (vg_replace_malloc.c:195)
==20420==    by 0x80483D8: main (jig.c:10)
==20420== 
==20420== LEAK SUMMARY:
==20420==    definitely lost: 0 bytes in 0 blocks
==20420==    indirectly lost: 0 bytes in 0 blocks
==20420==      possibly lost: 0 bytes in 0 blocks
==20420==    still reachable: 0 bytes in 1 blocks
==20420==         suppressed: 0 bytes in 0 blocks

See in my project I use malloc like this:

malloc(sizeof(some_structure) * some_expression);

at one point some_expression gives value 0 so indirectly i am doing

   malloc(0)

So when I am not going to malloc a single byte so I am not making free it but in that case valgrind shows memory leackage. Why?

Edit :

If I use like this:

char *a = malloc(0);

Then a is not NULL. So question is why not NULL? & Which address it stores?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:47:26+00:00Added an answer on May 26, 2026 at 4:47 am

    From my malloc(3) manpage (Linux):

    If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().

    So there’s no guarantee that malloc is not allocating any space when you pass it 0, and you have to free the pointer that it gives you if it isn’t NULL.

    If malloc does not return NULL, you get a buffer that you can’t use for anything, but since it has a unique address, malloc must have allocated at least one byte.

    Maybe you’d want to replace the malloc call with one to

    // like malloc, but guarantees NULL return value if n==0
    void *malloc0(size_t n)
    {
        return n ? malloc(n) : NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get the memory usage statistics of a tomcat server using
What's the difference between the following three .htaccess rules and when to use each,
I'm trying to create a self-signed wildcard SSL certificate for use on a number
I am creating a calendar table for my warehouse. I will use this as
<tt:TooltipExtender ID=teAutoServiceShutdown TargetControlID=cbAutoServiceShutdown Parser Error Message: Could not load file or assembly 'AjaxControlToolkit, Version=3.0.20820.16598,
I've been searching for a way to draw a black-and-white array on screen. It's
I am facing a small issue which i am not able after trying so
I'm trying to use haxr 3000.8.5 to upload images to a WordPress blog using
Database : Oracle 11g VS 20120 Provider: ODAC 11.2 Release 4 and Oracle Developer
I'm trying to fit a 20x20 table into a view using a programmatically built

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.