2,609 questions
Advice
0
votes
5
replies
47
views
Anyone knows fr good temp mobile services?
For my little business, im looking for a solid service to receive sms online for account verifications. tried a few like smsfast and free-sms-receive,(something like that, don't really remember) but ...
0
votes
0
answers
73
views
Can I free a `PangoContext` after creating a layout on it?
I'm making a library function to measure text. However, it can't take a PangoLayout or anything to do with Pango except the font used.
My current solution is just to create one for use specifically ...
2
votes
2
answers
130
views
Is it undefined behaviour to free a `static restrict` array function parameter?
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 ...
-6
votes
2
answers
306
views
How to try catch finally in c
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";
...
4
votes
2
answers
238
views
How to free the value inside struct in c
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() {
...
2
votes
3
answers
218
views
Writing a Von Neumann Ordinal generator in C : Problem with malloc
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 ...
3
votes
2
answers
186
views
Is it safe to call free on std::string_view::data?
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 ...
0
votes
2
answers
170
views
How can I call free and set the pointer to NULL inside a function correctly and why?
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 ...
3
votes
2
answers
138
views
Custom free function doesn't release memory completely, Valgrind reports 'still reachable'
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 ...
1
vote
2
answers
130
views
Leak errors in fifo application in c
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"
#...
3
votes
1
answer
122
views
Why cant I free the char buffer after assigning the last index to null terminator (\0) [duplicate]
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 ...
5
votes
6
answers
915
views
Decent ways to handle malloc failure?
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(*...
1
vote
0
answers
86
views
Not able to merge free blocks together in my simple, custom, memory allocator
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 ...
1
vote
1
answer
146
views
What happens if you call free() on non allocated memory returned by a function
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 ...
0
votes
2
answers
164
views
Freeing a dynamically allocated string with an internal null byte
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() ...