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 8526189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:12:07+00:00 2026-06-11T08:12:07+00:00

I freed a pointer that I made, but Valgrind still reports that I’ve lost

  • 0

I freed a pointer that I made, but Valgrind still reports that I’ve lost bytes, so I’m not really sure how to approach it.

The code in question Is:

listNode* temp = (listNode*)malloc(sizeof(listNode));
node = list->head;
while (node != NULL)
{
    temp = node->next;
    free(node->entry);
    free(node);
    node = temp;
}
free(temp);

With the valgrind output:

16 bytes in 1 blocks are definitely lost in loss record 13 of 21
==2137==    at 0xB823: malloc (vg_replace_malloc.c:266)
==2137==    by 0x100001B1E: freeList (main.c:110)
==2137==    by 0x100001CB5: main (main.c:157)
  • 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-06-11T08:12:09+00:00Added an answer on June 11, 2026 at 8:12 am

    You don’t free the memory allocated with malloc in the code given, unless node == NULL. You allocate a block of memory, assign it to temp, then go on in the loop to reassign to temp other addresses, losing the memory that you’ve allocated with malloc.

    It doesn’t look like you need the malloc at all: you’re just using temp as a temporary pointer: why do you need to allocate memory for it?

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

Sidebar

Related Questions

malloc: *** error for object 0x10ee008c0: pointer being freed was not allocated *** set
For example, if I wanted to write a free that nulled the pointer, I
I am aware of that All associated result memory is automatically freed at the
I have a made a simple program that reproduces the problem: #include <boost/archive/text_oarchive.hpp> #include
I have a simple doubly linked list example that I'm working on, but for
I have a class that implements an interface, which is made available for plugins.
I have made the decision to use monotouch to develop an application that browses
I have a class that derives from a C struct. The class does not
I made a very minimal javascript bookmarklet (~1 KB minified) that lets me play
I'd like to define a pointer type that is shared between device and host

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.