Questions tagged [invalid-pointer]

30 questions
0
votes
2 answers

C: Realloc invalid pointer?

This is my task from school: Write a function ​insertString ​that inserts the string s2 into s1 at index n.s1 has been allocated using malloc and should be resized (the function is void again). The program gave me a NULL on PC and when I switched to…
0
votes
1 answer

How to resolve 'munmap_chunk(): invalid pointer Aborted' when using strchr

I am writing a function in C using strchr. Basically, given a string from parameter, the code will identify any '\n' exists in (char content[]) and copy the string before '\n' to str using strncpy. String after '\n' is copied using strchr. The…
Calmen Chia
  • 325
  • 1
  • 8
0
votes
2 answers

Why does finite recursive behaviour cause a crash ? (free(): invalid pointer)

Below is my code just a function called kk that will be recursively called for 10 times so impossible to cause stack overflow, but it crashes with Error in `./3': free(): invalid pointer: 0x0000000000602100 Who knows the reason?? string…
Caiyi Zhou
  • 143
  • 1
  • 9
0
votes
1 answer

undefined behaviour to use raw pointer from a deleted shared_ptr?

I have following code #include #include #include int main() { void* p_any = nullptr; { auto p_src = std::make_shared(10); // new instance p_any = p_src.get(); …
rnd_nr_gen
  • 2,203
  • 3
  • 36
  • 55
0
votes
0 answers

How to find the invalid pointer in a C++ tree program?

My program is simple, make a tree (min heap), and through a inorder traversal to store data to an array, then destroy the tree (heap). When I run to the store step, the program crash. I can't find why, even I know the bug position (I comment some…
0
votes
0 answers

dlopen fails to load library, invalid pointer

I have a library "libqscr.so", that I load into my program during the runtime using dlopen. It was working perfectly, after I rebooted my PC, dlopen started giving me this error: *** Error in `/path/to/program': realloc(): invalid pointer:…
Nafees
  • 509
  • 4
  • 16
0
votes
1 answer

Templated Dequeue invalid pointer: Fails on deleting class

My templated queue's dequeue function works fine for a queue of string, but if I use my custom Robot class, it crashes upon trying to delete the pointer. I'm curious as to why. For example, in main.cpp #include #include…
Wezabi
  • 3
  • 3
0
votes
1 answer

Delphi XE3 Invalid Pointer when trying to free FSQL (TStringList)

I'm creating a new app in XE3 but using some units created in D2007. I"m getting an error when freeing a TStringList data item. Here's the code that creates the data item FSQL: procedure TPayorDM.DataModuleCreate(Sender: TObject); begin FPayorDRM…
Rich R
  • 367
  • 4
  • 15
-1
votes
1 answer

Does returning a pointer from a function make it invalid to reallocate?

So I'm currently trying to write a C program to track the longest word(s) from argv. It's been going great! Until I tried to reallocate a character double pointer, it seems to think it's an invalid pointer. The exact error I'm getting is; realloc():…
-1
votes
4 answers

Invalid pointer after a call to delete

I have this simple code in a file called virtual.cpp: #include class Parent { public: virtual ~Parent(){ std::cout << "Parent Destructor" << std::endl; } virtual void VirtualFunction() { std::cout <<…
vaeVictis
  • 484
  • 1
  • 3
  • 13
-1
votes
2 answers

Why does this C code give me a segmentation fault?

Using the CS50 library, this is my code but it keeps giving me a segmentation fault. I have tried to figure out where it keeps doing a segmentation fault, and for some reason it has to do with my function. Why does it keep doing this? #import…
-1
votes
3 answers

What exactly happens when I do buffer1.push_back(buffer2.front()) in C++?

Help me understand this. Here is the context. I am writing a program in C++. I have 2 buffers (deque). Let's call them buffer1 and buffer2; I have 2 threads: one thread is filling buffer1 with random values. The other one is copying the oldest…
Filipe Santos
  • 61
  • 2
  • 9
-2
votes
1 answer

Valgrind gets stuck in infinite loop

While testing a C programming project I encountered this error: realloc(): invalid pointer I tried to find the cause of the problem using Valgrind. When when I ran the code in Valgrind, it got stuck in an infinite loop in a different part of my…
joephek09
  • 11
  • 1
-3
votes
2 answers

C free variables used with strtok

I already saw post similar to this one, but I found a little difference that drive me in the wrong way. I have this code: char * token_one = strtok(my_buffer, " ,.-"); char * token_two = strtok(NULL, " ,.-"); free(token_one); free(token_two); I…
user4789408
  • 1,196
  • 3
  • 14
  • 31
-3
votes
1 answer

invalid pointer when passing string in c++

I have two c++ classes, let's call one hier and the other one cp. During startup, hier creates an instance of cp. cp reads in a text file with two columns, which are called resp_r and resp_l, and stores the contents in two arrays of the same name.…
musterschüler
  • 171
  • 2
  • 6
1
2