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

The Archive Base Latest Questions

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

this is part of my code which reads an http response. It’s supposed to

  • 0

this is part of my code which reads an http response. It’s supposed to increase the buffer size if it runs out of room. But i keep getting access violations. It happens when copying the data to the new buffer: memcpy(tmp_alloc, rec, ResponseLength); Any help/suggestions are appreciated.

#define SERVER_CHUNK 1024

char *rec = new char[10000];
char in_buff[SERVER_CHUNK];
int in_sz, 
    ResponseLength = 0, 
    rec_len = 10000;

in_sz = recv(ss,in_buff,SERVER_CHUNK,0);//get the response  

while(in_sz > 0)
{           

    memcpy(rec + ResponseLength,in_buff,in_sz);
    ResponseLength += in_sz;

    if((ResponseLength + SERVER_CHUNK) > rec_len)
    {
        char *tmp_alloc = (char*) malloc (ResponseLength + SERVER_CHUNK); 
        if(!tmp_alloc)
        {   
            printf("failed to alocate memory!\n");
            break;
        }
        memcpy(tmp_alloc, rec, ResponseLength);
        free(rec);
        rec = tmp_alloc;
        rec_len = ResponseLength + SERVER_CHUNK; 
    }

    in_sz = recv(ss,in_buff,SERVER_CHUNK,0);    
}   
  • 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-14T01:04:11+00:00Added an answer on May 14, 2026 at 1:04 am

    It’s possible that you’re corrupting the heap by mixing new[] with free(), which is not supported.

    Change:

    char *rec = new char[10000];
    

    To:

    char *rec = (char*) malloc( 10000);
    

    and see if it makes any difference.

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

Sidebar

Related Questions

It's a part of larger code base, which forces -Werror on gcc. This warning
Note : The code in this question is part of deSleeper if you want
I am trying to learn and writting this part of code. while testing few
this problem is part of a bigger page but I've simplified the code to
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
I'm trying to reteach myself some long forgotten math skills. This is part of
This is a part algorithm-logic question (how to do it), part implementation question (how
How can I extract the part of this stream (the one named BLABLABLA) from
I'm working on a document application and part of this application I've to add
I'm writing an app to help facilitate some research, and part of this involves

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.