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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:58:18+00:00 2026-06-12T13:58:18+00:00

Windows 7, 64bit, MinGW toolset, following code: m_data = reinterpret_cast<SampleType *>(realloc(m_data, m_size + v));

  • 0

Windows 7, 64bit, MinGW toolset, following code:

m_data = reinterpret_cast<SampleType *>(realloc(m_data, m_size + v));  
if (NULL == m_data){  
    perror ("realloc failed");  
    exit(-1);  
}

fails with the message realloc failed: Not enough space
It happens even if I asked 100 bytes more. And no matter whether I use malloc (with the correspondind pointer reaasignment) or realloc. I always get the same.
The computer reports over 1GB available free memory.

Above is fragment of the method. Below is its entire code.
The point is that this method allocates memory first time when this method has m_data equal to NULL and enlarges it in cosenquent calls. So, pls, see below

Wave & operator+= (const Wave wave){
    if (NULL != m_data){
        m_data = reinterpret_cast<SampleType *>(realloc(m_data, m_size + wave.DataSize()));
        if (NULL == m_data){
        perror ("realloc failed");
        exit(-1);
        }
    } else {
        m_data = reinterpret_cast<SampleType *>(malloc(wave.DataSize()));
        m_size = 0; // just for sure
    }
    /* this code fragment I used instead of realloc's one to prove that realloc is not a root of error cause
    SampleType *t_buf = reinterpret_cast<SampleType *>(malloc(m_size + wave.DataSize()));
    if (!t_buf) {perror ("malloc failed"); exit(-1);}
    memcpy (t_buf, m_data, m_size);
    free (m_data);
    m_data = t_buf;
    */
    memcpy (m_data + m_size, wave.SampleBuffer(), wave.DataSize());
    m_size += wave.DataSize();
    return *this;
};

So, in first time a memory is allocated using malloc. Don’t doubt.

Debugger session trace.

Breakpoint 2, _fu17___ZSt4cout () at ../sound_windows/Sound.h:192  
192             if (NULL != m_data){  
(gdb) print *this  
$2 = {static CHANNEL_NUMBER = <optimized out>, m_format = {wFormatTag = 1, nChannels = 2,nSamplesPerSec = 44100, nAvgBytesPerSec = 176400, nBlockAlign = 4,  
    wBitsPerSample = 16, cbSize = 18}, m_duration = 0, m_data = 0x0, m_size = 0}  
(gdb) cont  
Continuing.  

Breakpoint 2, _fu17___ZSt4cout () at ../sound_windows/Sound.h:192  
192             if (NULL != m_data){  
(gdb) print *this  
$3 = {static CHANNEL_NUMBER = <optimized out>, m_format = {wFormatTag = 1, nChannels = 2,nSamplesPerSec = 44100, nAvgBytesPerSec = 176400, nBlockAlign = 4,  
    wBitsPerSample = 16, cbSize = 18}, m_duration = 0.00451559993, m_data = 0x75d9e0, m_size = 800}  
(gdb) cont  
Continuing.  
tried to allocate 800+100 bytes  
realloc failed: Not enough space  
[Inferior 1 (process 6132) exited with code 037777777777]  
  • 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-12T13:58:19+00:00Added an answer on June 12, 2026 at 1:58 pm

    The root of cause of the error was stack destruction happened due to mess in memory addressing in memory management functions. For example, in the following code line

    memcpy (m_data + m_size, wave.SampleBuffer(), wave.DataSize()); 
    

    m_data + m_size means not what it was intended because m_data points to a two byte size type while m_size is size in bytes. So m_data + m_size offsets poninter not to the end of m_data but on to the distance twice far.

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

Sidebar

Related Questions

I have the following scenario: - 64bit Windows Server 2008. - 32bit .NET application
I've tried the code below on both Windows (64bit) and Linux(32bit). I was sure
(Running MingW on 64-bit Windows 7 and the GCC on Kubuntu) This may possibly
When trying to install my 32bit service on a Windows 64bit machine my installer
Main OS is windows 7 64bit. Using VM player to create two vm CentOS
I use Windows 7(64bit) and repeat steps in Google Document . This is what
I've instaled MySQL workbench in Windows 7 64bit. Unfortunately, I'm facing problems: In the
I get this exception on my Windows 7 64bit in application running in VS
I'm using IE9 on a Windows 7 64bit machine. For testing, i've disabled my
I got my WAMP installed on my windows 7 64bit. cURL is not working,

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.