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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:20:05+00:00 2026-05-18T23:20:05+00:00

I have a list in C that is something like this: typedef struct _node

  • 0

I have a list in C that is something like this:

typedef struct _node
{
   int number;
   DWORD threadID;
   HANDLE threadH;
   struct *_node next;
} *node;

And you have somthing like this:

node new_node = malloc(sizeof(node));

As you may have guessed out, this list will store information for threads, including their handlers and Id’s. Still I am having trouble when I try to do this:

free(new_node);

Everytime I try to do this I encounter an unexpected error, VS saying that there was a data corruption. I’ve pinned down as much as possible and I found that the problem resides when I try to use free the handle.
I’ve searched on MSDN how to do this but the only thing I can find is the function that closes the thread (which is not intended here, since I want the thread to run, just deleting it’s record from the list).

The question is: how I am supposed to free an handle from the memory? (Considering that this is only a copy of the value of the handle, the active handle is not being deleted).

EDIT: This is the function to insert nodes from the list:

int insereVisitanteLista(node* lista, DWORD threadID, HANDLE threadH, int num_visitante)
{
    node visitanteAnterior;
    node novoVisitante = (node)malloc(sizeof(node));

    if(novoVisitante == NULL)
        return 0;

    novoVisitante->threadID = threadID;
    novoVisitante->threadH = threadH;
    novoVisitante->number = num_visitante;
    novoVisitante->next = NULL;

    if(*lista == NULL)
    {
        *lista = novoVisitante;
        return 1;
    }

    visitanteAnterior = *lista;

    while(visitanteAnterior->next != NULL)
        visitanteAnterior = visitanteAnterior->next;

    visitanteAnterior->next =novoVisitante;
    return 1;
}

And this is the function to delete nodes:

int removeVisitanteLista(node * lista, DWORD threadID)
{
    node visitanteAnterior = NULL, visitanteActual;

    if(*lista == NULL)
        return 0;

    visitanteActual = *lista;

    if((*lista)->threadID == threadID)
    {
        *lista = visitanteActual->next;
        visitanteActual->next = NULL;
        free(visitanteActual);

        return 1;
    }

    while(visitanteActual != NULL && visitanteActual->threadID != threadID)
    {
        visitanteAnterior = visitanteActual;
        visitanteActual = visitanteActual->next;
    }

    if (visitanteActual == NULL)
        return 0;

    visitanteAnterior->next = visitanteActual->next;
    free(visitanteActual);

    return 1;
}
  • 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-18T23:20:05+00:00Added an answer on May 18, 2026 at 11:20 pm

    What exactly is a node that you are trying to free? Is this a pointer to a struct _node? If yes, have you allocated it previously? If no, free is not needed, otherwise you have to check if node is not NULL and make sure you do not free it multiple times. It is hard to guess what you are doing and where is an error without a minimal working example reproducing the problem. The only thing I can suggest is to read about memory management in C. This resource might help.

    UPDATE:

    node in your code is a pointer to _node. So sizeof (node) is a size of a pointer, which is either 4 or 8 bytes (depending on architecture). So you allocate 8 bytes, for example, but assume you have a pointer to the structure which is much larger. As a result, you corrupt memory, and behavior of the program becomes undefined. So changing node novoVisitante = (node)malloc(sizeof(node)) to node novoVisitante = (node)malloc(sizeof(_node)) should fix the problem.

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

Sidebar

Related Questions

Some existing web services I consume have methods that look something like this: List<Employee>
I want that list, because if something horrible happens, and I'll have to reinstall
Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have
I have a list that looks like (A (B (C D)) (E (F))) which
I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I have a specialized list that holds items of type IThing : public class
I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have a list wrapper that maintains two Tstringlists and a TClassList I need
I have a list view that is periodically updated (every 60 seconds). It was
i have a list of regex patterns (stored in a list type) that I

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.