Questions tagged [free]

free is a function to deallocate memory obtained from malloc and other functions in C. Do not use this tag to refer to free software. Asking for software recommendation is off-topic on Stack Overflow. If you have a question about free software, you can ask here: https://softwarerecs.stackexchange.com/

Filter by
Sorted by
Tagged with
0 votes
0 answers
4 views

Certbot failed to authenticate some domains (authenticator: apache). The Certificate Authority reported these problems:

here is my subdomain : http://django.arifsultani291.digital. here is the error details : Certbot failed to authenticate some domains (authenticator: apache). The Certificate Authority reported these ...
Arif Qasemi's user avatar
1 vote
2 answers
76 views

Memory slice using malloc by slicing one big malloc'd memory

Consider an application that invokes malloc() and free() many times. The application allocates a total of say 1000 bytes in total. I am trying to write a code where we reduce number of malloc / free ...
Programmer's user avatar
  • 8,387
0 votes
4 answers
138 views

Proper memory free for pointers inside struct C

I have a struct list which contains a dynamic array of type struct pair, and each element of this array points to two variable of type struct element. In the main of my program I allocate, via a ...
fdv's user avatar
  • 73
-2 votes
0 answers
67 views

Java good practices to "free" memory [duplicate]

I'm trying to understand if referencing a variable to null is a good practice or not in Java to help the garbage collector to identify freeable objects. When I call a method and I instantiate a new ...
lucoski's user avatar
1 vote
2 answers
81 views

Definitely lost memory even though I free in C

I want to create a function that, when given a struct with a pointer in it to another struct of the same type, it finds all of the pointers and frees them. The struct would be: typedef struct example_ ...
Jason's user avatar
  • 27
1 vote
1 answer
45 views

Trying to understand a `pointer being freed was not allocated` error in C

So the error is self explanatory, but I don't understand how I'm getting it. I made the malloc and now the free complains. I'm trying to build a map/hashtable for myself. I'm newish to C but not ...
Justin808's user avatar
  • 21k
1 vote
0 answers
42 views

monty pop opcode in C

I did all I could, debugged for over 24hrs, and still could not fix this bug. I am trying to implement the pop opcode of a monty intepreter. Testing with test.m file: push 1 push 2 push 3 pall pop ...
scisamir's user avatar
0 votes
2 answers
95 views

free(): double free detected in tcache 2 Aborted

#include <stdlib.h> #include <stdio.h> #include <string.h> void ffree(char **pp) { if (!pp) return; char **a = pp; while (*pp) { free(*pp); // Free the ...
Abelrahman hussein Ragab's user avatar
0 votes
0 answers
53 views

How to free memory returned by glxChooseFBConfig?

glxChooseFBConfig returns GLXFBConfig* and GLXFBConfig is defined this way: typedef struct __GLXFBConfigRec *GLXFBConfig; Here is an example function which uses glxChooseFBConfig and frees memory: ...
Irbis's user avatar
  • 1,260
0 votes
1 answer
97 views

Is it possible to release the 2D array without a for loop?

#include <stdio.h> #include <stdlib.h> void* create2dArray(int r,int c) { int (*arr)[c] = (int(*)[c])malloc(sizeof(*arr) * r); return arr; } void release2dArray(void* arr) { ...
Zhiren Zhou's user avatar
0 votes
3 answers
132 views

Is it always safe to `free` a pointer returned by `malloc`?

My understanding is that it's allowed to call free with a pointer returned by a call to malloc (or any other function returning a pointer to some memory dynamically allocated on a heap, like strdup or ...
Maciek's user avatar
  • 1,706
-1 votes
1 answer
44 views

Do java programmers need to deallocate memory for jni object

There is a class using JNI. Some code like below public class JniUser { private String name; private int age; public native int getAge(); public native String getName(); } In native ...
Juneyoung Oh's user avatar
  • 7,376
-1 votes
2 answers
96 views

Delete node in the linked list

Given the head of a linked list and an integer val, remove all the nodes of the linked list that have Node.val == val, and return the new head. This is my attempt struct ListNode *removeElements(...
iskander's user avatar
4 votes
1 answer
227 views

Can I free() something in C that has been malloc()'ed in C++?

I'm writing a wrapper for a library written in C++, such that it can be used from C. In the wrapper code I'm making lots of copies of the underlying data of c++ containers. E.g. if the c++ library ...
mortelsson's user avatar
0 votes
2 answers
92 views

Exception occurred, segmentation fault while using free() in c;

My code somehow ran but it was not giving an expected outcome, so to understand it I started debugging and it shows an exception occurred, a segmentation fault at the line where I'm using free(). Here'...
Nishu Patel's user avatar
0 votes
1 answer
42 views

Given OpenSSL's int return style error handling, how can I handle errors in OpenSSL functions without leading to memory leak? [duplicate]

This question leans toward the "design" aspect of things, but I wanted to know how others might have dealt with this issue and might do so now considering current programming trends in C. So ...
z.karl's user avatar
  • 295
1 vote
1 answer
106 views

memory leak after free?

I have noticed the program I have been testing leaks memory at two different points, no matter if I call free() or not. I don't understand why it's happening and how it could be fixed. I am using ...
DravStart's user avatar
0 votes
2 answers
66 views

Where should I put "free(BlockOfMemory)" in this code?

#include <stdio.h> #include <stdlib.h> int main() { int *numbers = malloc(5 * sizeof(int)); // Speicherplatz auf 10 ints vergrößern int *temp = realloc(numbers, 10 * sizeof(...
AhmetPesli's user avatar
0 votes
1 answer
41 views

How are types like pthread_mutex_t implemented in C?

I want to bring some of those properties to types created by me, if possible. More specifically I want to know more about these: How is it possible the code doesn't compile if I try to manually ...
Ernaldo's user avatar
  • 152
0 votes
1 answer
69 views

In C, how to store and free in the heap a multidimensional map, with rows and columns?

I'm trying to build a data structure, using the C language, which allows me to record strings (representing altitude values) whose data describe some characteristics of points in a map. Each point ...
Federico Porciello's user avatar
0 votes
2 answers
101 views

Is there a function(s) to copy a string into a new space in memory [closed]

If I want to copy the string "Best School" into a new space in memory in C programming, What statement(s) can I use to reserve enough space for it? I have tried using this: malloc(strlen(&...
Frank Okey's user avatar
0 votes
0 answers
9 views

Is there a website with "embedded plugins"?

As I am using WordPress.com (special version) with no plugin support, I have a hard time implementing a couple of elements I would like. I found out the ability to add Facebook chat through JavaScript ...
J G's user avatar
  • 1
1 vote
1 answer
93 views

free() on char* recognized as invalid by valgrind

I am attempting to free char* pointers that exist within a char** array, but valgrind is determining this operation as invalid. Here is a simple example of what I'm doing: struct building{ int ...
smellyourbooks's user avatar
-3 votes
2 answers
67 views

How can i return and also free memory at the same time

i have a function that allocates memory, then fills it with data and then returns it. i want to free this allocated memory but if i free it before return it will return null, also if i try to free ...
Alper Tangil's user avatar
1 vote
1 answer
99 views

Problem freeing memory in a fancy hash table

I am taking cs50 and I have this pset where I should implement a hash table to load words in a dictionary to check the spelling of words in a text, it's like a word spelling check. I had the idea to ...
Pyro's user avatar
  • 38
7 votes
5 answers
235 views

What is a good coding practice for freeing allocated resources at failure/exit points in C?

I'm working on a school project and the teacher asked us to free all resources at program's termination. I'm struggling to find a way to write more readable and/or less code to manage that, ...
Ernaldo's user avatar
  • 152
0 votes
2 answers
84 views

Why free linked list with two temporary variables in c?

I am going through the CS50 course, and this last part of code was written by the instructor to free the memory used : ptr = list; while (ptr != NULL) { node *next = ptr->next; free(ptr); ...
Celes's user avatar
  • 3
0 votes
1 answer
66 views

Segmentation fault (core dumped) after free(), but I have used malloc()

I'm learning memory allocation in c, and tried the following function, not in main(). // Functions void manipulateMemory(void) { char *string1 = malloc(5 * sizeof(char)); // Try to play with ...
Ricky's user avatar
  • 13
0 votes
1 answer
49 views

Places to host Java WAR projects for a portfolio? Cheap or Free

Does anybody know of any sites that let you host java .war project files for free or cheap? I want to host some applications for a portfolio, so I'm not looking for the most robust service. I'm aware ...
Bob Ross Jr's user avatar
2 votes
2 answers
81 views

How to advance pointer in order to shorten a string?

I am creating a char array (representing a string) and adding characters to the array from the end of the array. But I don't know how many characters I will be adding in total ahead of time. Once I ...
dayuloli's user avatar
  • 16.4k
1 vote
1 answer
79 views

Why does free() cause a program crash in this code?

I've already searched for an answer to this, but so far haven't come up with anything that answers the specific question, so asking here. I have some C code that dynamically allocates space for a ...
Mark Edwards's user avatar
4 votes
5 answers
107 views

minor improvement in freeing nodes in linked list in C

Look at this code that wants to free all the malloced nodes inside a linked list in C: ptr = list; while (ptr != NULL) { node *next = ptr->next; free(ptr); ptr = ...
Dr Linh Chi Nguyen's user avatar
1 vote
2 answers
40 views

Weird assert failure after a struct free in C [duplicate]

I am a beginner in C and I encountered this weird assert failure: assuming we have this setup: #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <assert.h> ...
bongadonga's user avatar
0 votes
1 answer
58 views

Freeing struct with unclosed file in C

I don't have much experience in C, my question is as follows: if I have a struct like this: typedef struct { FILE* file; ... ... } MyStruct; and a function to free this struct: void ...
EpsilonCode's user avatar
0 votes
0 answers
65 views

c, failing to completely free this linked list

im trying to free this linked list but for some reason visual studio memory usage always shows me that 5 or 6 extra allocations stay with each iteration of the program. this is the function i use to ...
Code Bom's user avatar
-3 votes
3 answers
85 views

Program exits without any error when I try to free a 2d matrix in a struct

I create and fill my 2d array of unsigned char in my struct using parser of a file that contains numbers separated by spaces #include <stdio.h> #include <stdlib.h> #include <string.h>...
Vinicius Caetano's user avatar
0 votes
1 answer
49 views

Double free or corruption freeing queue in C

I have a queue (In Linux, C) that uses the following structs: typedef struct Packet { char buffer[600]; int32_t buf_length; } Packet; typedef struct Node { Packet *packet_p; struct ...
Biribu's user avatar
  • 555
0 votes
1 answer
102 views

Double free in C implementation of Queue

Here is my implementation of a Queue class in c, the struct queue_object* contains a void* object and a queue_object* next. Adding char 'A' and 'B' seems to work out, polling once too, but at the ...
chiefsteve's user avatar
0 votes
1 answer
112 views

Why is freeing pointers resulting in weird behavior and crashed?

I created linked lists in C and a few functions to help me with them. #include <stdio.h> #include <stdlib.h> typedef struct { int value; void *next; } Node; Node *NewNode(int ...
Imaginary's user avatar
-3 votes
1 answer
72 views

Need help cleaning memory leaks and resolving segmentation fault in C code using malloc and free

I've been working on this code in C and it has lots of leaks that I don´t know how to clean. What I want when I call get_next_line on main is for it to return the next line of a .txt file. Can ...
deboracaracol's user avatar
0 votes
2 answers
25 views

Local logs display

I'm working on a little side project that has 3 microservices (running locally). Each service write logs to a local file. I was wondering if there's any free, local easy-to-setup tool that I can use ...
Opl Itay's user avatar
0 votes
0 answers
12 views

.pcap file cannot be read using vlpgrabber

I am having another (below) issue while reading .pcap file using vlpgrabber: double free or corruption (out) Aborted (core dumped) void VLP16::Start(std::string pcapName) { mVlpGrabber = boost::...
Zaki's user avatar
  • 1
1 vote
0 answers
135 views

How can I correctly free dynamically allocated memory for a linked list

At the moment I am doing a project for school where I have to store info about some teams using a linked list which contains a number of dynamically allocated fields(a list containing data about the ...
AnghelutaVlad's user avatar
3 votes
2 answers
202 views

ntdll!RtlIsZeroMemory releasing linked list memory in C [warning: Critical error detected c0000374]

I am trying to write data with a linked list structure. After writing the function used to apply memory for each node in the linked list, I started writing the function used to release memory for each ...
S-N's user avatar
  • 316
1 vote
1 answer
316 views

Why am I getting free(): invalid pointer error?

I'm writing a program which generates arrays with different properties and different sizes, bubble-sorts them, counting comparisons and swaps number, and prints the result for each sequence and each ...
noko's user avatar
  • 11
-1 votes
1 answer
124 views

Why does child process leak memory in C after killing it?

I need to terminate the child process at the end of the (if) block. However killing it causes memory leak Tried on ubuntu terminal. compile: gcc -W -Wall -Wextra mallocFork.c run: valgrind ./a.out #...
mate istvan's user avatar
0 votes
1 answer
61 views

Can Azure free tier app service connect exeternal APIs?

I have created an app service and hosted an API. I would like to connect with external API like push notification and payment gateways. Will the free tier supports to connect external APIs from Azure ...
Saravanan Somasundaram's user avatar
0 votes
1 answer
51 views

Do I need to free something in a linked list in C that has been malloced if I freed the entire node?

So I was writing a program with linked lists in C and I was using the free function and I was wondering why this does not create a segmentation fault because I didn't free name. Is it because the free ...
Wolfking's user avatar
  • 103
0 votes
2 answers
70 views

Freeing memory from dynamically created 2d char array

Below is how i declare my array const int SIZE = 128; char line[SIZE]; char **lineArray = NULL; char **lineArray = malloc(count * sizeof(char*)); for (int i = 0; i < count; ++i) { ...
Hayden Parker's user avatar
0 votes
2 answers
122 views

Is this malloc/free pair leaking memory?

I'm new to C. #include <stdio.h> #include <stdlib.h> #include <string.h> void demo() { char* s = malloc(10); strcpy(s, "foo"); free(s); } int main() { ...
ntk138's user avatar
  • 21

1
2 3 4 5
52