0

I'm getting a valgrind memory leak report for CS50's Speller problem.

==28709== LEAK SUMMARY:
==28709==    definitely lost: 0 bytes in 0 blocks
==28709==    indirectly lost: 0 bytes in 0 blocks
==28709==      possibly lost: 0 bytes in 0 blocks
==28709==    still reachable: 134,307 bytes in 1,159 blocks
==28709==         suppressed: 0 bytes in 0 blocks

I've managed to solve the speller problem but the valgrind problem remains.

I tried debugging my codes but still didn't succeed so I tried to run the original untouched codes, the same exact error with same exact value kept occurring.

I even tried to remove the speller.c content, leaving only an empty main() inside but still the same error.

// Implements a spell-checker

#include <ctype.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/time.h>

#include "dictionary.h"

// Undefine any definitions
#undef calculate
#undef getrusage

// Default dictionary
#define DICTIONARY "dictionaries/large"

// Prototype

int main(int argc, char *argv[])
{
    // Success
    return 0;
}


// Implements a dictionary's functionality

#include <stdbool.h>
#include <stdio.h>
#include "dictionary.h"

// Represents a node in a hash table

// Number of buckets in hash table
const unsigned int N = 1;

// Returns true if word is in dictionary else false
bool check(const char *word)
{
    // TODO
    return false;
}

// Hashes word to a number
unsigned int hash(const char *word)
{
    // TODO
    return 0;
}

// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
    // TODO
    return true;
}

// Returns number of words in dictionary if loaded else 0 if not yet loaded
unsigned int size(void)
{
    // TODO
    return 0;
}

// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
    // TODO
    return true;
}

I'm not sure what to do next, any help will be appreciated, thanks.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
Erwin
  • 1
  • What operating system are you using? Which compiler? Which version of Valgrind? Have you tried adding the options that Valgrind suggests? – Paul Floyd Nov 22 '20 at 06:26
  • When you get that information, you need to rerun Valgrind with extra options to find out about where that leak occurs. Especially if you're using a Mac, you may have a leak from the Mac C runtime — that would be unsurprising. But you have to find where the leak occurs and only then can the correct action be determined. – Jonathan Leffler Nov 22 '20 at 06:27
  • You may want to look at [CS50 pset5 speller line 54 conditional jump error](https://stackoverflow.com/a/64364090/3422102) and [CS50 Speller Segmentation Fault Issue During Misspelled Words](https://stackoverflow.com/a/63681299/3422102) – David C. Rankin Nov 22 '20 at 08:26
  • I'm using CS50 IDE which is on Linux. I've tried -v as suggested by Valgrind but it's still beyond my understanding. Fortunately, turns out after I tried again I can submit my assignment without triggering memory error check. The still reachable leak still exists but at least for now I can move on to another assignment. Thank you everyone for the help! – Erwin Nov 22 '20 at 08:40
  • This is a very good problem set and important for understanding hash-tables and memory handling. The links I posted (especially the second one) may really be worth your time. – David C. Rankin Nov 22 '20 at 08:42
  • Thank you David, I've read the links, I'll try to tinker around my codes again to see if I can improve something – Erwin Nov 22 '20 at 08:55

0 Answers0