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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:23:11+00:00 2026-05-14T02:23:11+00:00

I am getting a stack overflow in one of the recursive functions i am

  • 0

I am getting a stack overflow in one of the recursive functions i am running..

Here is the code..

void* buddyMalloc(int req_size)
{ 
     // Do something here
     return buddy_findout(original_index,req_size); // This is the recursive call
}

void *buddy_findout(int current_index,int req_size)
{
    char *selected = NULL;

    if(front!=NULL)
    {
        if(current_index==original_index)
        {
            // Do something here
            return selected;
        }
        else
        {
            // Do Something here
            return buddy_findout(current_index+1,req_size);
        }
    }
    else
    {
        return buddy_findout(current_index-1,req_size);
    }
}

Consider the initial value of index to be 4. and it first do index-1 till it reaches 0 index. and then it comes back to index 4 by incrementing..This is wht i want to implement.
But it gives a stack overflow with memory map in the command prompt :

Here is the output from my shell :

*** glibc detected *** ./473_mem: free(): invalid pointer: 0x00c274c0 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb50ff1]
/lib/tls/i686/cmov/libc.so.6[0xb526f2]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb557cd]
./473_mem[0x8048b44]
./473_mem[0x8048b74]
./473_mem[0x8048b74]
./473_mem[0x8048944]
./473_mem[0x8048c87]
./473_mem[0x8048d31]
./473_mem[0x8048f79]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xafcb56]
./473_mem[0x8048671]
======= Memory map: ========
0017c000-00198000 r-xp 00000000 08:01 5224       /lib/libgcc_s.so.1
00198000-00199000 r--p 0001b000 08:01 5224       /lib/libgcc_s.so.1
00199000-0019a000 rw-p 0001c000 08:01 5224       /lib/libgcc_s.so.1
00260000-00284000 r-xp 00000000 08:01 1927       /lib/tls/i686/cmov/libm-2.10.1.so
00284000-00285000 r--p 00023000 08:01 1927       /lib/tls/i686/cmov/libm-2.10.1.so
00285000-00286000 rw-p 00024000 08:01 1927       /lib/tls/i686/cmov/libm-2.10.1.so
006cd000-006e8000 r-xp 00000000 08:01 6662       /lib/ld-2.10.1.so
006e8000-006e9000 r--p 0001a000 08:01 6662       /lib/ld-2.10.1.so
006e9000-006ea000 rw-p 0001b000 08:01 6662       /lib/ld-2.10.1.so
00aa9000-00aaa000 r-xp 00000000 00:00 0          [vdso]
00ae6000-00c24000 r-xp 00000000 08:01 1900       /lib/tls/i686/cmov/libc-2.10.1.so
00c24000-00c25000 ---p 0013e000 08:01 1900       /lib/tls/i686/cmov/libc-2.10.1.so
00c25000-00c27000 r--p 0013e000 08:01 1900       /lib/tls/i686/cmov/libc-2.10.1.so
00c27000-00c28000 rw-p 00140000 08:01 1900       /lib/tls/i686/cmov/libc-2.10.1.so
00c28000-00c2b000 rw-p 00000000 00:00 0 
08048000-0804a000 r-xp 00000000 00:14 2176       /media/windows-share/OS/Project2/473_mem
0804a000-0804b000 r--p 00001000 00:14 2176       /media/windows-share/OS/Project2/473_mem
0804b000-0804c000 rw-p 00002000 00:14 2176       /media/windows-share/OS/Project2/473_mem
08483000-084a4000 rw-p 00000000 00:00 0          [heap]
b7600000-b7621000 rw-p 00000000 00:00 0 
b7621000-b7700000 ---p 00000000 00:00 0 
b7716000-b7819000 rw-p 00000000 00:00 0 
b7827000-b782a000 rw-p 00000000 00:00 0 
bfb96000-bfbab000 rw-p 00000000 00:00 0          [stack]
Aborted

Thanks in advance
adi

  • 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-14T02:23:11+00:00Added an answer on May 14, 2026 at 2:23 am

    Look at your compiler docs to see if it has “tail recursion” optimization.
    (Though now your stack overflow problem becomes an infinite loop problem!)

    gcc -foptimize-sibling-calls ...
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using JQuery from Google CDN and I've been getting stack overflow error (using
Reading through the existing unit testing related threads here on Stack Overflow, I couldn't
We use the excellent validator plugin for jQuery here on Stack Overflow to do
I was just messing around to answer someone's question here on Stack Overflow, when
What methods are there for automatically getting a stack trace on Unix systems? I
I've seen a few mentions of this on Stack Overflow, but staring at Wikipedia
I happend to go through the below site from one of the Stack over
This is my first question on Stack Overflow. Apologies in advance if I don't
I've noticed RAII has been getting lots of attention on Stackoverflow, but in my
I keep getting stuck conceptually on deciding an Exception-handling structure for my project. Suppose

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.