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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:06:26+00:00 2026-06-11T16:06:26+00:00

I am relatively new to the idea of pointers and C, so I apologize

  • 0

I am relatively new to the idea of pointers and C, so I apologize if this is a really simple problem. I am trying to free a singly linked list from memory that is created. The singly list is created fine, but I am having trouble free it from memory, I get a segmentation fault. Any ideas where I am going wrong? I need to have separate methods for both freelist and freenode. Avail is a global pointer variable and is part of the code that I’m sure works. The problem exists in free list and I’m just not sure where.

   void freelist(olnode **list) {
   olnode *ptr = *list;
    while (*list != NULL) {
     ptr = *list
     freenode(&ptr);
     ptr = ptr->next;
    }
   }

   void freenode(olnode **ptr) {
    if(*ptr != NULL) {
     (*ptr)->next = avail;
     avail = *ptr;
     *ptr = NULL:
    }
   }
  • 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-11T16:06:27+00:00Added an answer on June 11, 2026 at 4:06 pm

    Freenode sets the pointer passed to it to NULL. Afterwards freelist tries to dereference the pointer which is now null. That’s where the program crashes.

    Besides that, your program doesn’t really free any data. It just changes the pointers pointing to the data to point to NULL. That means the memory will stay allocated and isn’t available for new data. To mark the memory a pointer points to as no longer needed, you need to call the free() method from the standard library on the pointer which points to it. Setting the pointer to NULL afterwards is not needed, but a good practice to make sure that any subsequent try to access the free’ed memory location results in a predictable crash and not in totally unpredictable behavior.

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

Sidebar

Related Questions

Hi I am relatively new to this topic so I have no idea if
I feel like this is a simple question, but I am still relatively new
Relatively new to MVC and trying to get a cascading dropdown list working for
Relatively new to rails, I'm working on a simple rails app for a few
I'm relatively new javascript, but I am comfortable in other languages. I'm trying to
I'm relatively new to Java and I'm still trying to understand the fundamentals. I
I am a long-time code developer, but relatively new to IntelliJ Idea. Within a
I'm still relatively new to XCode. I'm trying to build an iPhone application and
New to Android and OpenCV. Been trying to to implement code from new book,
I am relatively new to the whole idea for HTML parsing/scraping. I was hoping

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.