c++ - std::bad_alloc thrown when vector's push_back() is used -


in following snippet of code, error saying: terminate called after throwing instance of 'std::bad_alloc' what(): std::bad_alloc aborted (core dumped)

this occurs @ push_back() instruction. reason? error seen in first iteration not think because program has overused memory. may overlooking silly. please let me know!

for(i=0; i<numsegs; i++){     for(j=0;j<rvm->number_segs; j++){         if(segbases[i] == rvm->segment_list[j]->ext_data_seg){             transaction->rvm = rvm;             transaction->tid = trans_count++;             transaction->number_regs = 0;             transaction->number_segs++;             rvm->segment_list[j]->modified = 1;             temp_seg = rvm->segment_list[j];                                        transaction->segment_list.push_back(temp_seg);         }     }  } 

the loop runs numsegs = rvm->number_segs = 1.

edit: transaction structure is:

struct trans_t{     int tid;     rvm_t rvm;     int number_segs;     int number_regs;     vector <segment*> segment_list;     vector <region*> region_list;    }; typedef struct trans_t* trans_t; 

the main problem appears stated in comments: if indeed structure of type trans_t (which not pod) allocated using malloc (as op commented), whole program malformed.

as constructors trans_t::segment_list<> never run, trying push cause either crash or exception. here, quite possible "value size" parameter passed standard allocator exceeds max_size() of allocator (because it's garbage in), throws bad_alloc upon receiving argument.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -