Questions tagged [free]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
18 views

Week 4 lecture: calling free() after malloc() removes destination contents

In the lecture of week 4 in CS50x, David shows how to allocate memory using malloc() to clone a string, and how free() needs to be called whenever malloc() was called to free up allocated memory ...
0 votes
1 answer
182 views

free_family does not work properly | INHERITANCE

I have executed following code for free family function - void free_family(person *p) { // TODO: Handle base case if(p->parents[0] == NULL && p->parents[1] == NULL) { ...
  • 86
1 vote
1 answer
16k views

PSET5 compiles but gives: "free(): double free detected in tcache 2" error on testing

Been scratching my head at this for a while now. I use FREE() only once in the program, and don't know why I get this error. Any help is appreciated :-) // Implements a dictionary's functionality #...
0 votes
1 answer
105 views

pset5 - speller "double free detected" when I run check 50 but program does nothing during self tests

I am currently doing Speller. I have written all the functions and the program compiles but during self testing it is printing "misspelled words" and stays stuck at a blinking cursor. It ...
0 votes
1 answer
195 views

Lab5 free_family function

I have created the below function to free memory allocated by the create_family. // Free `p` and all ancestors of `p`. void free_family(person *p) { // TODO: Handle base case if(p == NULL) ...
0 votes
1 answer
48 views

Struggling with PSET5 Speller valgrind problems (& possibly more)

I've been working on PSET5 for weeks now on & off and I'm becoming really frustrated. I think I'm lacking some understanding of the malloc/free relationship, I'm not sure. Here's all of my code. ...
0 votes
2 answers
70 views

Speller program runs accurately with memory leaks. When I add free() to correct memory leak, program stops executing

My speller program runs and produces accurate outputs. It passes all but one of the check50 checks. It fails because it has a memory leak. I added free() to the load loop where I am allocating ...
0 votes
1 answer
42 views

Speller - not sure what's wrong

I'm struggling trying to find what the error is or why speller is behaving the way it is. Currently, when I run help50 valgrind, I get this error message: ==8634== 56 bytes in 1 blocks are definitely ...
0 votes
1 answer
33 views

pset4 speller trie segmentation fault

I am doing the trie version of speller in pset4 and keep getting a segmentation fault. I have run my code on short dictionaries and short text files and it seems to work just fine but when I try ...
  • 3
0 votes
1 answer
284 views

Unload works on small dictionary, but not on large? (speller.c / hash table method)

When testing with the small dictionary, it unloads as expected however when testing with the large dictionary, I receive the error "Could not unload dictionaries/large." The only difference that I've ...
0 votes
1 answer
79 views

pset5 (trie) valgrind memory leak

I'm having trouble with the last step of pset5, valgrind. When I run it with the test text I get: Looks like you're trying to access 8 bytes of memory that isn't yours? Did you try to index into an ...
  • 21
0 votes
1 answer
777 views

PSET4: free(): invalid next size (fast)

So as the title says, I'm trying to do the pset4 where I get this error when I try to execute the program. I've searched the forum and also Reddit, and I understood that I've some issue with the ...
  • 13
0 votes
1 answer
66 views

Pset5 Unload Giving Double Free or Corruption error

My title pretty much explains the problem. I can tell that the problem probably exists where I called free (marked in my code). Here's the code below: bool unload(void) { node* trav = head; ...
  • 182
0 votes
1 answer
31 views

How/when to free this memory? (pset6/server)

Here is my implementation of the indexes function in pset6: char* indexes(const char* path) { char* php = "index.php"; char* html = "index.html"; char* pathCopy = malloc(strlen(path) + ...
  • 3
0 votes
1 answer
58 views

check50 fails on caesar.c when using free()

I have a little problem. I can get get this to pass all the checks, but only if I remove the free() statement on L71 Link to code removed by andy5995 If I leave the free() statement in, this is ...
  • 302
0 votes
1 answer
74 views

Pset6 - CS50. Segmentation fault for free(index)

For pset6, implementing a server, almost everything works except the indexing function. I get a segmentation error after the use of this function when trying to free(index). This is the returned ...
  • 13
0 votes
1 answer
711 views

per valgrind: multiple invalid read and invalid write; invalid free(); "still reachable: 568 bytes in 1 blocks"

My recover.c seems to recover all images correctly (per check50) but still seems to have issues with a couple of things per valgrind (output copied at the bottom). As background, I am using a ...
  • 47
0 votes
1 answer
88 views

Pset6 Indexes free() invalid next size error

I'm getting this error when I try to run my server. I don't what's been causing it. char* indexes(const char* path) { char* path_php = malloc(sizeof(char) * strlen(path)); char* path_html = ...
0 votes
1 answer
8k views

Invalid pointer error when using free()

I was trying to practice malloc'ing and freeing memory, however when I run the free() function in this program an error is returned for an invalid pointer. Can anyone tell me what I'm doing wrong? ...
  • 17
0 votes
1 answer
78 views

pset5 root node not freed

It looks like my unload function is not working properly. Valgrind shows 0 errors, but when I print out the address of my root node, it is not NULL. Hence my unload function (which returns true if ...
  • 115
0 votes
3 answers
310 views

Is vmware free or chargeable?

I am studying CS50 through edx.org In order to solve pset1, I have to download vmware workstation. However, the software is not free and the website is requesting me to pay 200 USD. Is vmware free ...
1 vote
1 answer
43 views

spellchecker unload not freeing 1 block

What is not freeing!? [code snipped by mod] // end of load function (mod comment) return true; fclose(dict_file); } [code snipped by mod]
0 votes
1 answer
590 views

pset 05 trie large dictionary unload issue

I am working through pset5 (Mispellings) using a trie and I am stumped. This is the error exactly from gdb (sample is a text file I made and works just fine with the small dictionary): Starting ...
  • 1
0 votes
1 answer
172 views

Trie Spellchecker unload() - two allocs not freeing

My freeNode() function goes through each child of my root node and free()'s each of them from the bottom back up to the root. Two of the allocs are not being free()'d. #include <stdbool.h> #...
  • 25
0 votes
2 answers
680 views

Why can't I call the function "free" to release memory!

Help! I am using malloc to create an array on the heap... but I can't seem to get the compiler to recognize the call to "free"! /******************************************** * Program Name: ...
1 vote
0 answers
2k views

Valgrind says "Invalid read of size 4" while freeing memory recursively in a trie

My PSET "mispelling" works fine and contains no memory leak but when I run the program with Valgrind it says Invalid read of size 4. My unload function calls a deleteTrie function which looks like ...
  • 55
0 votes
2 answers
400 views

pset6-unload free() : invalid pointer

i get everything working but the unload function, there seems to be something wrong with free() here' the code: void freeChild(node* curr) { if(curr == NULL) return; for(int i = 0; i &...
1 vote
1 answer
291 views

segfault while freeing memory in speller

I'm having an enormous problem implementing the unload function for the speller in pset6. Although it's not a well-polished algorithm I first wanted to make a quick design that allows me to take a ...
  • 23
0 votes
1 answer
64 views

valgrind free and leaks

In the continued lecture of week 5, it is stated that if we don't free memory in our programs, this can lead to a memory leak. But, just to be clear, when my program exit, all the memory used by my ...
  • 157
3 votes
1 answer
18k views

How to free a nested struct?

In preparation for my final project, I am writing a C program that handles task lists. It utilizes a nested struct. For every line it reads from a file it creates a struct of type task. Each task then ...
2 votes
1 answer
128 views

Should We Free Memory Allocated By GetString()?

Running valgrind with line 42 commented out shows that there are indeed some leaks. If we DON'T comment out line 42, then there are no leaks. Here is the code // copy-1.mp4 from Week4 Walkthroughs //...