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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:35:52+00:00 2026-05-31T08:35:52+00:00

I’m currently playing with linked lists, and I’ve put together the following code for

  • 0

I’m currently playing with linked lists, and I’ve put together the following code for testing purposes.

First I’d like to point out, I’m aware of my unusual list setup, it was just a test, to get a not upside down list. My actual “problem” now is, that I don’t seem to have any memory leaks once the program terminates, although I’m not freeing the list. I’m using drmemory on Windows for analyzing, and it always worked nicely. If I put some other mallocs in this code, it notices the not freed memory. Why doesn’t it notice the list?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// ----------------------

typedef struct Item
{
    char name[10];
    struct Item *next;
} Item;

Item *items = NULL;

Item *items_add(const char* name)
{
    Item *new = malloc( sizeof(Item) );
    strcpy(new->name, name);
    new->next = NULL;

    if(items == NULL)
    {
        items = new;
    }
    else
    {
        Item *iter = items;
        while(iter->next != NULL)
        {
            iter = iter->next;
        }

        iter->next = new;
    }

    return new;
}

void items_rem(const char* name)
{
    if(items == NULL)
        return;

    Item *iter = items, *prev;
    do
    {
        if(strcmp(iter->name, name) == 0)
        {
            prev->next = iter->next;
            free(iter);
            break;
        }

        prev = iter;
        iter = iter->next;
    }
    while(iter->next);
}

// ----------------------

int main(void)
{
    items_add("Item1");
    items_add("Item2");
    items_add("Item3");
    items_add("Item4");

    items_rem("Item3");

    for(Item *iter = items; iter != NULL; iter = iter->next)
    {
        printf("%s\n", iter->name);
    }

    /*
        Output:
            Item1
            Item2
            Item4
    */
}
  • 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-31T08:35:53+00:00Added an answer on May 31, 2026 at 8:35 am

    The reason, I can think of is that Item *items = NULL ‘items’ is a global variable. So, as far as the memory leak checking tool is concerned, the memory is still accessible from the code, so it may be assuming that you still need that memory.

    Atleast IBM Rational Purify works in this way. In IBM Rational Purify, you can select the option to show “Memory in use” and it will display this pointer and number of bytes held by it.

    Please note that a memory is considered leaked only when there are no pointer variables containing that address and it has not been freed also.

    For Ex:

    int main()
    {
      function();  
    }
    
    int function()
    {
       char *ptr = NULL;    
       ptr = malloc(10);     
       return 0;    
    }
    

    Now, in the above example, once you return from function, there is no way for you to access variable ptr. So, the memory allocated for ptr is definitely lost

    • 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&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.