Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
93 views

I'm asking this question from the perspective of a compiler developer – I want to know whether a particular potential optimisation is valid (because all programs that the optimisation would break have ...
ais523's user avatar
  • 2,384
-4 votes
0 answers
102 views

While implementing a Dijkstra-Search on a Graph, I call a seperate method to perform the search, handing it a pointer to my nodes and direct values for start/endpoint and array size. Notably,t he ...
Tom Tom's user avatar
-6 votes
2 answers
274 views

I want to try catch the free(hello); so that the free(world); can still be executed for freeing all allocated memory in the main program. int main() { const char *hello = "Hello World"; ...
stackbiz's user avatar
  • 1,914
4 votes
2 answers
224 views

I don't know how to reset the value field inside the Hello struct. It's a pointer pointed to an outside passed input argument. typedef struct Hello { void *value; } Hello; Hello* create_hello() { ...
stackbiz's user avatar
  • 1,914
2 votes
3 answers
206 views

I want to write a computer programme that will do the following things : 1a. It will make an array 3 characters long. £££ 2a. It will then initialize the array with the string "{_}" and ...
uran42's user avatar
  • 469
3 votes
2 answers
166 views

Is it safe to call free in the example below: size_t len = 10; char* buffer = static_cast<char*>(malloc(len)); std::string_view sview(buffer, len); free(sview.data()) Why do I need this? I have ...
Njrslv-yndx-cloud's user avatar
0 votes
2 answers
156 views

I am confused about &str[0], which is equal to str. If I can do str = NULL, why can’t I do &str[0] = NULL or why does it not work? Also, since free(str) and free(&str[0]) both work to free ...
iliass's user avatar
  • 19
3 votes
2 answers
127 views

I've been following an article that walks through implementing primitive versions of malloc and free. After finishing the allocator, I wanted to test it using Valgrind, so I added the following lines ...
younessBct's user avatar
1 vote
2 answers
121 views

I'm not sure why my valgrind is spitting heap errors and I've been tracing my code left and right. I have some code, but I'm not sure if more code is needed. My jobs.h #include "piper.h" #...
minyoung heo's user avatar
3 votes
1 answer
119 views

I'm just confused as to why this keeps giving me an error. If I just fread the file in and don't assign the last index to the null terminator, I can free the memory after using it. However, if I do ...
Aidan's user avatar
  • 87
5 votes
6 answers
534 views

Suppose that I need to malloc three times and I would like to make an early return if one of the malloc calls have failed. My first try: void test(void) { int *a, *b, *c; a = malloc(sizeof(*...
Doohyeon Won's user avatar
0 votes
0 answers
53 views

I am facing a problem in my application. I'm using the Office Viewer to view office files, but when the document loads, it appears with its own options bar (for example, to create a copy or turn on ...
Carolina Castillo's user avatar
1 vote
0 answers
50 views

I am trying to implement a simple memory allocator. Essentially trying to copy the function malloc() and free(void *ptr) in C. I initialize a region of memory using sbrk(). In my custom malloc ...
Kamrul Hassan's user avatar
1 vote
1 answer
136 views

I am writing some random code and I wanted to know if there is there anything that defines how freeing memory returned like this works or if it is just undefined behavior. struct a *get() { static ...
FenrirBots's user avatar
0 votes
2 answers
129 views

The following code allocates 256 bytes for a character array and then replaces the space with \0 (similar to what strtok and strsep do). #include <stdlib.h> #include <string.h> int main() ...
9-Pin's user avatar
  • 482
1 vote
1 answer
175 views

I am not from a computer science background and have been trying to learn Data Structures using C programming. I have made some binary tree programs and realised that I have used malloc() left and ...
Vinayak Deshmukh's user avatar
0 votes
0 answers
45 views

I've looked at Auth0 and firebase, but both these options always either require you to store a client secret on both machines or active user interaction. Basically the thing I had in mind is just the ...
Semanresu's user avatar
2 votes
0 answers
94 views

Could someone please explain this error? It craps out when I try to free the array. It works fine when I malloc inside of main so I'm guessing its because of the function scope? I thought if I ...
user2980746's user avatar
2 votes
3 answers
149 views

Question: if I have a pointer to "ints" struct as seen below and I cast it to void and back does that mean I'm not allowed to free it anymore? How does free keep track of the allocation ...
user2980746's user avatar
3 votes
4 answers
181 views

Say I have a function that allocates some struct (object) and has to allocate additional data when setting its fields. Since each allocation can fail, the object creation may only partly succeed. What ...
user6163780's user avatar
-1 votes
3 answers
122 views

Ok, I know reading a buffer after free'ing it is wrong. I was trying to prove a point that free() does not touch the data stored in the buffer, but I am unable to prove it :) Here is the code: #...
yyyyy's user avatar
  • 71
2 votes
0 answers
223 views

I built an automated WhatsApp birthday wishing bot using whatsapp-web.js that works perfectly on my local machine. The bot is scheduled to check a database at 8 AM every day for birthdays and sends ...
Osajere Finney's user avatar
1 vote
1 answer
97 views

Im confused on why is this code freeing list but not tmp after setting list to point to where tmp points (list = tmp;) // Implements a list of numbers with an array of dynamic size #include <stdio....
Guilherme Cintra's user avatar
0 votes
2 answers
103 views

This is the full code I have right now. I have tried everything that I could think of, but when I have the contents of the else block, despite the code skipping through it, the code runs smoothly with ...
amegyoushi's user avatar
1 vote
0 answers
95 views

Apologies in advance for the code dump, I can't really think of another way to show my issue properly. For a school project I have to make a bakery simulation and since it has to fit within certain ...
LangleyMann's user avatar
0 votes
4 answers
169 views

I was recently exploring ll the oop features of C, when i came to this issue. I want to create a game engine with C, so i use nested structs to organize ewerything. But when freeing the memory, the ...
TheTrueJerome's user avatar
4 votes
2 answers
181 views

I'm trying to make a DTC in C. This is the structure of the nodes: typedef struct node { int value; struct node *lower; struct node *higher; } node; To free the memory allocated using ...
Sarvesh Pande's user avatar
3 votes
2 answers
194 views

I want to test my code in low memory situations. I wrote this function with setrlimit to limit the available memory : unsigned short int oom_enable = 0; char* _oomfill = NULL; uint32_t oom_setup(...
François Cerbelle's user avatar
1 vote
2 answers
277 views

A simple program to allocate and free heap memory: int main(int argc, char **argv) { char *b1, *b2, *b3, *b4, *b_large; b1 = malloc(8); memset(b1, 0xaa, 8); b2= malloc(16); memset(...
rdre8's user avatar
  • 49
0 votes
1 answer
131 views

I have 2 variants of code: 1st: void PrintMem(const int* memarr,const size_t size) { for (size_t index = 0; index < size; ++index) { std::cout << '<'<<(index+1)<<&...
vansergh's user avatar
  • 101
2 votes
1 answer
111 views

A function that returns a 2D list of pointers to every possible knight movements on a grid. Everything works except my spacial free function that crashes in random locations: Unhandled exception at ...
yuval gabay's user avatar
0 votes
1 answer
130 views

I've got a TWebGridPanel component that I'm dynamically populating with rows and columns as well as controls within those rows and columns. My issue is that I need to clear/delete/destroy all controls ...
Shaun Roselt's user avatar
  • 4,361
1 vote
1 answer
124 views

In the last reading of the file, when it still has to return a line, and the line variable has the content of that line, an invalid pointer error occurs when doing free in the main but that line has ...
Manuel's user avatar
  • 11
0 votes
1 answer
41 views

typedef struct partition_struct { int* elements; int last; //last element index int dim; //n allocated int } partition; typedef struct partitions_struct { partition* partitions; ...
SKOP_'s user avatar
  • 3
2 votes
1 answer
126 views

In the get_next_line function, I am using the pointer temp to free the memory allocated for leftover after it is being modified by strchr. if I remove temp, the function leaks, but as it is now, I am ...
Clément's user avatar
  • 101
0 votes
1 answer
73 views

I have these structs: typedef struct Nodo{ int id_nodo; struct Nodo *next; } Nodo; typedef struct{ Nodo *head; } inmap; //Struct Grafo typedef struct { int N; // numero dei nodi del ...
Samuele Bertucci's user avatar
0 votes
2 answers
141 views

I have tried solving this problem by googling about calloc() and realloc(). I saw videos about it.I read similar cases in stackoverflow but due to C++ and struct usage I had trouble understanding how ...
Sotiris's user avatar
  • 21
1 vote
1 answer
144 views

I wrote a recursive function in C to free memory allocations made by a program that generates a tree of nodes. However, I can't work out how it works - but it does pass the check50. Perhaps I've not ...
MattJC7's user avatar
  • 13
-2 votes
1 answer
99 views

strutto *head,*cdm; head=&a; cdm=head; a.next=&b; b.next=&c; c.next=NULL; do{ printf("%d\n",cdm->dato); cdm=cdm->next; } while(cdm!=NULL); free(a); free(b); ...
Valentin Constantin's user avatar
0 votes
0 answers
101 views

I recently tried to examine how malloc() and free() populate the address space with differently sized chunks of memory on my system. It is a debian linux with the glibc malloc implementation and 4 GB ...
led's user avatar
  • 156
0 votes
0 answers
39 views

I don't understand how to free() the strings in my array char** When I try to do it in this code I got a segfault and 40 bytes lost with valgrind int main(void) { char **strs; char *...
Plaket's user avatar
  • 1
1 vote
1 answer
50 views

I'm currently tackling the Advent of Code 2022 Day 9 challenge and encountered an unexpected issue with freeing a dynamically allocated linked list in my C program. Although my code runs smoothly ...
fish_brain's user avatar
0 votes
1 answer
87 views

I have followed a few tutorials for hashmaps in c. From the code you can probably tell I relied heavily on this implementation which has a nice follow up video where he revisits it to show how he ...
Surfytom's user avatar
1 vote
2 answers
63 views

Here's a snippet of C code: int main() { void **values = calloc(10, sizeof(void *)); int *a = malloc(sizeof(int)); *a = 100; int *b = malloc(sizeof(int)); *b = 200; values[0] ...
shayan rok rok's user avatar
1 vote
2 answers
93 views

This is my first post on StackOverFlow, I was writing the code for a linked list in C, when suddently stumble upon a situation i have no solution for (located in dupstring function). This is my ...
José Gomes's user avatar
0 votes
1 answer
44 views

when my process double free, I get some print, I wonder those info print by who ? if I donot need it, can I close the print? // g++ hel.cpp #include <iostream> int main() { int *p = new int;...
ryryss's user avatar
  • 1
2 votes
1 answer
170 views

I have a big project in C that has somewhere around 2 thousand lines of code. I have in this project a linked list that I am using to store data of the program, at the end of the program I am calling ...
roee's user avatar
  • 105
0 votes
1 answer
97 views

I'm trying to free all the memory allocated in testing_malloc() with the method testing_free(). I am using a Google Test project to test my code and the MemoryLeakDetector mentioned in this answer. ...
RF Eggnine's user avatar
-1 votes
2 answers
108 views

I am allocating a struct with a function pointer. Obviously, I have to free the struct at the program end. However, freeing a function pointer leads to undefined behavior. How should I do it? I tried ...
Gideon Kogan's user avatar
2 votes
0 answers
94 views

I am trying to parse a query string, feeding the method with this: char array[] = "address=NYC&port=3359&username=JDoe&password=Secret*"; Here is my code (I have included the ...
Franziee's user avatar
  • 649

1
2 3 4 5
53