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

  • SEARCH
  • Home
  • 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 3794640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:57:38+00:00 2026-05-19T12:57:38+00:00

I’m running valgrind to look for memory leaks. I have alloc’d two global variables

  • 0

I’m running valgrind to look for memory leaks. I have alloc’d two global variables in the main function; then, at the end of main I free both, but Valgrind keeps writing:

==18311== 16 bytes in 1 blocks are definitely lost in loss record 1 of 2
==18311==    at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==18311==    by 0x804A30C: main (application.c:730)
==18311== 
==18311== 16 bytes in 1 blocks are definitely lost in loss record 2 of 2
==18311==    at 0x4025BD3: malloc (vg_replace_malloc.c:236)
==18311==    by 0x804A31D: main (application.c:731)

Leak summary:

==18311== LEAK SUMMARY:
==18311==    definitely lost: 32 bytes in 2 blocks
==18311==    indirectly lost: 0 bytes in 0 blocks
==18311==      possibly lost: 0 bytes in 0 blocks
==18311==    still reachable: 0 bytes in 0 blocks
==18311==         suppressed: 0 bytes in 0 blocks

Why I can’t free these two variables?

Edit

someList *something; *something_else;

The struct used has two fields of type char * and a field someList *next.
Later there’s a lot of code. A few threads are going to add/edit/delete objects using this two variables.

something -> object 1 -> ... -> object n
something_else -> object 1 -> ... -> object m

Where -> means that something->next = object 1, and object k are all instances of someList *.

Near the end of the application, I freed every field of each object k element. Then, in the last part:

free(something);
free(something_else);

It’s possible that I forgot to free a field of an object. Can this cause the behavior I’m having here?

I hope it’s clearer, now.

  • 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-19T12:57:39+00:00Added an answer on May 19, 2026 at 12:57 pm

    For each malloc() call you typically need a corresponding free() call, in order to avoid memory leaks. For optimal memory usage, you should free() each allocated memory block as soon as possible after being done with it.

    In your case, you have two malloc() calls in application.c:730 and application.c:731, for which there is no free() call made by the time your program terminates. Therefore, the memory blocks allocated there are not freed. This causes a memory leak that Valgrind detects and reports.

    Unless you provide us with some code and/or more information on your program there is no way for us to help you more.

    EDIT:

    There are two interesting lines in your Valgrind output:

    ==18311==    definitely lost: 32 bytes in 2 blocks
    ...
    ==18311==    still reachable: 0 bytes in 0 blocks
    

    You have definitely “lost” two memory blocks and there no pointers to them at the time your program terminates. This means that the pointers to these two blocks were in fact overwritten or otherwise lost their value during the course of your program.

    A common cause of this issue is storing the result of two malloc() calls to the same pointer without an intermediate free() call. Another possible cause is a changed pointer value due to pointer arithmetic operations – Valgrind makes an effort to detect some of these cases, but it is not always successful, depending on your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.