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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:46:28+00:00 2026-05-20T12:46:28+00:00

I have the following code: struct VRfile{ char sessionID[10]; char file[20]; int first; };

  • 0

I have the following code:

struct VRfile{    
    char sessionID[10];    
    char file[20];    
    int first;    
};    

std::map (int ,struct VRfile *) maps;
struct VRfile *vrinfo = (struct VRfile*)malloc (sizeof(struct VRfile*));
 strcpy(vrinfo->sessionID, sessionId.c_str());  
  strcpy(vrinfo->file, filename.c_str());  

 socketmap.insert(std::pair(int , struct VRfile *) (thisfd,vrinfo));

I’m getting an error at the socketmap.insert(std::pair(int , struct VRfile *) (thisfd,vrinfo)); line:

Error: *** glibc detected *** memory corruption: 0x080aa7b0 ***  
/lib/libc.so.6[0x6222dd]  
/lib/libc.so.6(__libc_malloc+0x67)[0x623e97]  
/usr/lib/libstdc++.so.6(_Znwj+0x27)[0x45d7ab7]  

backtrace:  
0  0x002eb402 in __kernel_vsyscall ()  
1  0x005e0df0 in raise () from /lib/libc.so.6  
2  0x005e2701 in abort () from /lib/libc.so.6  
3  0x0061928b in __libc_message () from /lib/libc.so.6  
4  0x006222dd in _int_malloc () from /lib/libc.so.6  
5  0x00623e97 in malloc () from /lib/libc.so.6  
6  0x045d7ab7 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6  

Then it points to the line of code I have mentioned above. Can nyone tell me why this is happening?

  • 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-20T12:46:29+00:00Added an answer on May 20, 2026 at 12:46 pm

    You’re not allocating enough space for your structure—you’re only allocating a pointer’s worth (4 or 8 bytes, depending on your pointer size), when in fact you should be allocating somewhere on the order of 36 bytes (specifically, sizeof(VRfile). So, you’re stomping on the heap by writing random values into it (a so-called heap overrun), which is messing up the data structures used by malloc to track memory. When it detects this corruption, it throws its hands up and terminates your program.

    However, since this is C++ and not C, you should really be using operator new instead of malloc to allocate dynamic memory. You don’t have to deal with the size of the memory you’re allocating, it’s implicit in the variable type. Secondly, there’s no reason to always say struct VRfile instead of just VRfile—that’s only needed in plain C code (not C++), and only when there isn’t a proper typedef (which there usually is).

    So, just write this:

    VRfile *vrinfo = new VRfile;
    

    And of course, when you delete your map (or remove any element from it, for that matter), make sure to delete each value in it to avoid leaking memory. For example:

    // This could also be implemented using a functor and std::for_each
    for(std::map<int, VRfile*>::iterator iter = maps.begin(); iter != maps.end(); ++iter)
        delete iter->second;
    maps.clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: struct B { //B() {} int x; int y;
I have the following code: struct Node { int a; int b; }; Node
I have the following code struct Node { int accnumber; float balance; Node *next;
I have the following code: class outer { struct inner { int var1; int
I have the following code in a web.config file of the default IIS site.
Let's say I have the following code: struct mytype { ~mytype() { /* do
I have the following code, so far, I want to check if a file
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with

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.