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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:18:17+00:00 2026-05-26T17:18:17+00:00

This is a school assignment and I have most of it under control, but

  • 0

This is a school assignment and I have most of it under control, but there is a small part that is creating a memory leak and I have no more ideas on how to fix it.

We have created a memory allocator, and the trouble part are this two functions.

This first one cannot be modified

void destroy (){
  free():
  tot_alloc = 0; }

This second one is the one I’m working on

void free(){
  munmap(pool, PAGE_SIZE);
  Page* f = this;
  f = f->prev;
  if (f != NULL)
    f->destroy();
}

I have written all of the free() function and was asked in the assignment to call destroy().
I realize that this function is not destroying the first “this” because immediately is going to f->prev but I have no clue how to make it first destroy this and the go to prev.

I hope this is not a too silly question.

Many thanks!

Nico

  • 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-26T17:18:18+00:00Added an answer on May 26, 2026 at 5:18 pm

    To remove an element from a singly-linked list, you must walk to that element to find the element before it in the list. Then you have to ‘stitch’ around it. Like this:

    void free()
    { // Note: This has no error checking!
        Page *f = tail, *next_f = NULL;
        while(f != this)
        { // find this node to find the node after this node
            next_f = f;
            f = f->prev;
        }
    
        // found it. Now, next_f is the node after this node.
        // close the chain so this link can go away
        if (next_f == NULL) // there is no node after us, we must be the tail
           tail = prev; // the tail is now whatever node is after us
        else // in the node after us, the node before it is now the node before us
           next_f->prev = prev; 
    
        destroy(); // we are unlinked from the chain so can now be freed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this school assignment that I've been working on and am totally stumped
I have this code for a school assignment, but i can't manage to format
This isn't a school assignment or anything, but I realize it's a mostly academic
For a database assignment I have to model a system for a school. Part
i have an erd for a school assignment that contains a many to many
I am creating a file server application for school assignment. What I currently have
For an assignment at school, we have to use structs to make matrices that
For a school assignment, we have to make a Usecase diagram. But the documentation
I have an assignment for school that is really got the best of me.
I have for a school assignment created a small game, it is divided into

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.