Questions tagged [realloc]

C library function for reallocating a dynamically allocated memory region.

man page

Wikipedia

References

Related Tags

1717 questions
0
votes
3 answers

Realloc not expanding my array

I'm having trouble implementing realloc in a very basic way. I'm trying to expand the region of memory at **ret, which is pointing to an array of structs with ret = realloc(ret, newsize); and based on my debug strings I know newsize is correctly…
0
votes
1 answer

Maze Game in C corrupting. Possible Memory Leaks. Need help :)

I have developed this program which is a maze for a uni portfolio I have to do. I am having issues with an array of pointers to 'path' structures. I want to be able to dynamically change the size of the array with add_path. But whilst running the…
0
votes
3 answers

Does c++ realloc function applies delete operation for old data block if moving data to different block?

The function may move the memory block to a new location, in which case the new location is returned. For example I have a pointer to an array: int *arr; // somewhere next it initialized, filled with elements and etc Somewhere I need to: void*…
Kosmo零
  • 4,001
  • 9
  • 45
  • 88
0
votes
5 answers

Problems using "realloc" in C

I have code receiving string data from a socket which crashes on the first iteration: int size_data = 1024*sizeof(char); char *data = malloc(size_data); char *data_aux; int br_aux=0; int *nptr; memset(&data[0], 0, size_data); int br =…
Joe Lewis
  • 948
  • 5
  • 18
  • 34
0
votes
3 answers

C : freeing a reallocated pointer

I found out today that when I try to free a pointer that has been reallocated the program crashes and prints "Segmentation Fault". A realloc() is called on this pointer (array) in order to sizeup the array and merge the old array and another…
DennisVDB
  • 1,347
  • 1
  • 14
  • 30
0
votes
3 answers

C: realloc an array of string

I would like to reallocate an array of string with a function. I write a very simple program to demonstrate here. I expect to get the letter "b" to be output but I get NULL. void gain_memory(char ***ptr) { *ptr = (char **) realloc(*ptr,…
ldo
  • 91
  • 1
  • 6
0
votes
3 answers

realloc(): invalid next size: 0x0000000002119010

When I compile and run this code, I get an error. The error message is: realloc(): invalid next size: 0x0000000002119010 The file input has about 4000 words. I debugged it, but I can not find any problem. #include #include…
thlgood
  • 1,275
  • 3
  • 18
  • 36
0
votes
3 answers

Segmentation fault after realloc(). Can't assign allocated memory to pointer

I'm trying to allocate some memory with realloc(). This works so far. But if I want to assign the allocated memory to a pointer in a struct variable, I get a segmentation fault: // in header typedef struct { int a; char test[20]; }…
fondor
  • 153
  • 9
0
votes
1 answer

Heap Consistency error in C/Pro*C

I have following code that is working fine in my development environment but when the code is moved to production server it give oracle "Heap Consistency Error". Can you please let me know how to debug this and reason for this? if…
QMG
  • 719
  • 2
  • 7
  • 16
0
votes
2 answers

Reallocating memory for a struct array in C

I am having trouble with a struct array. I need to read in a text file line by line, and compare the values side by side. For example "Mama" would return 2 ma , 1 am because you have ma- am- ma. I have a struct: typedef struct{ char first,…
Zach Caudle
  • 145
  • 2
  • 13
-1
votes
3 answers

Realloc Invalid Pointer in C

This is a homework assignment so I don't want to post any code, but I'm pretty stumped with the bug that I have. Currently I have a array that has been malloced and am copying the pointer to the array. Now, I can memcpy and memmove with this array…
praks5432
  • 7,246
  • 32
  • 91
  • 156
-1
votes
1 answer

How Can I Know If This Program Works As i Intended( Dynamic stack )

enter code herei was watching a video in data structures in C , and when i understand the abstract view of the concept i go try implementing it without watching the implementation in the video , and what i implement wasn't in the video, the video…
-1
votes
1 answer

Why do I get Realloc() Error : invalid next size?

I when running the following code,I get Realloc() Error : invalid next size error #include #include #include #define ENLRAGE_SIZE(size) size = size + 10 int checkEndOfFile(); int numIsInArray(int *arr, int…
-1
votes
1 answer

Valgrind runs infinitely with realloc but code works

So, I am trying to copy char per char of a file in a chunk of memory that expands accordingly with the file's size... At the end the code print all ok, but if I use valgrind it will run forever. #include #include #include…
-1
votes
1 answer

Question about using malloc in 2d array with the the 1 dimension known in C

general question here. I came across a program that has one 2d array like this ps[i][j]. The problem is that i know the size of the j which is 3 but i dont know the size of i (hence the reason i want to use malloc and free(). How can i use the…
ZSR
  • 1
  • 2
1 2 3
99
100