Questions tagged [double-free]
94 questions
1
vote
0 answers
Understanding double-free mitre.org example
I'm trying to understand the following code example found on mitre:
#include
#include
#define BUFSIZE1 512
#define BUFSIZE2 ((BUFSIZE1/2) - 8)
int main(int argc, char **argv) {
char *buf1R1;
char *buf2R1;
char *buf1R2;
…

Enrico R.
- 21
- 5
1
vote
1 answer
Why I get double free?
Here is my code. I try to malloc the element that been malloc, and I don't know how to free them.
char *d = "apple";
int main() {
char *a = malloc(10 * sizeof(char));
char **b = &a;
strcpy(a,d);
printf("%c", *b[0]);
b[0] =…

tony Ding
- 13
- 3
1
vote
1 answer
C Keep Getting Double Free, despite trying to free in same form as allocation
Hey I'm trying to do a simple machine learning application for school but I keep getting double free for some reason I cannot even fathom.
float * evaluate(Network net,float * in)
{
int i,j;
float * out;
Neuron cur_neu;
…

Arthur Mograbi
- 21
- 3
1
vote
1 answer
Why do I get free(): double free detected in tcache 2 and aborted (core dumped)*
I am writing code to get the blood type for each generation. And it has a function, which frees the person and his ancestors, but I got those two errors:
free(): double free detected in tcache 2;
Aborted (core dumped).
Below is the code to free the…

Snowyaya
- 23
- 1
- 1
- 4
1
vote
2 answers
If a function returns a std::unique_ptr, is it reasonable to assume each returned value is to a new object?
I'm learning about std::unique_ptr, trying to grok what it represents.
Given a function (out of my control) that returns a unique_ptr, is it implied/well understood that each invocation returns a unique_ptr that points to a new object (different…

StoneThrow
- 5,314
- 4
- 44
- 86
1
vote
2 answers
segmentation fault while freeing pointer
class matrix
{
public:
int nrow;
int ncol;
double **m;
matrix(int r, int c)
{
nrow = r; ncol = c;
m = (double**)malloc(nrow*sizeof(double*));
for(int i=0; i
user9904784
1
vote
0 answers
GMock SetArrayArgument double free or corruption
Edit: I solved the double free error myself, however the question (question 1) why it behaves differently from command line and inside CLion still remains...
I am trying to use gmock and gtest. I want to mock a function that takes a pointer as an…

towadroid
- 11
- 4
1
vote
0 answers
How do I fix this double free or corruption (fasttop) error in my disk scheduling simulation C program?
Context: I am currently working on an assignment where I am to simulate a shortest-seek-time-first disk scheduling algorithm for a disk with 800 tracks and 1-5 track requests per file request (am supposed to enter 1000 file requests). I am using a…

lunastellae
- 47
- 4
1
vote
0 answers
Why a locale object would free a facet that was not created by it?
Pls pardon me, I'm a Chinese with very poor English skill. I hope I am expressing the things correctly.
I don't think that there is a necessary to free a obj by checking some type of reference count in the world of C++.
I believe that most c++…

Leon
- 1,489
- 1
- 12
- 31
1
vote
0 answers
Double free or corruption (out) with vector push_back of pair?
I have the follow bare bones main program:
#include "asd.h"
int main() {
asd a;
a.input();
}
Below is the asd file which is a class file:
#include "asd.h"
int maxlength = 256;
vector> t;
void asd::input() {
for…

UnknownUser
- 11
- 2
1
vote
1 answer
std::vector using back(), pop_back(), push_back(), get 'double free or corruption' error
I have the following code:
struct branchInfo{
Quaternion r;
Vector3 p;
std::vector branchPoints;
};
std::vector LSystem::Turtle(){
std::vector b;
// The axiom should always start with a '[' at…

JustHeavy
- 235
- 1
- 2
- 8
1
vote
2 answers
*** Error: double free or corruption (out): 0x00007fffe3465010 ***.Warning: Corrupted shared library list: 0x7ffea4000920 != 0x7ffff7ffd9d8
void *insert_rear_node(void *arg)
{
int *argument=(int *)arg;
int value=*argument;
//Assume that allocation is happening fine (Just like malloc , it is a custom heap allocator)
struct Node *head=(struct Node *) RTallocate(RTpointers,…

Keerthana Bysani
- 11
- 2
1
vote
2 answers
C++ double free error from function copy
I'm working through the Stroustrup C++ 11 book, and I ran into a double free exception. I understand that it's freeing the memory twice, but what I don't understand is why it's happening for a function that's passing by copy:
#include…

MrMowgli
- 873
- 7
- 23
1
vote
2 answers
Strange double free behavior
Below I have a function trim(). Which removes the leading zeros from an array of ints. It returns a pointer, which it receives from malloc(). While running a loop of successive calls to trim() and free(). I noticed that the value returned by trim()…

hermetik
- 115
- 9
1
vote
1 answer
double free or corruption when deleting reference
I have a class with some basic constructor. The code in main
C1 g = *new C1(2);
delete &g;
leads to error:
double free or corruption
Isn't this code equivalent to
C1 *g = new C1(2);
delete g;
What is that thing, that I don't understand.?

hungry91
- 133
- 8