Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memleak in C API #632

Closed
linas opened this issue Jan 17, 2023 · 1 comment · Fixed by #601
Closed

Memleak in C API #632

linas opened this issue Jan 17, 2023 · 1 comment · Fixed by #601
Labels
Milestone

Comments

@linas
Copy link

linas commented Jan 17, 2023

The program below leaks 64 bytes per spelling suggestion, or about a gigabyte in a few minutes. As far as I can tell, the program is written in exactly the style that the documentation calls for. Am I missing something?

This is on Debian stable, aspell version 0.60.8-3

I note that issue #600 reports a memleak, but its not clear if its the same issue. From what I can tell, the fix for #600 was never applied.

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <aspell.h>

// Compile with
// cc aspell-memleak.c -laspell

int main()
{
        AspellConfig *config = new_aspell_config();

        aspell_config_replace(config, "lang", "en_US");

        AspellCanHaveError *spell_err = new_aspell_speller(config);
        AspellSpeller *speller = to_aspell_speller(spell_err);

        size_t k=0;
        char* word = "asdf";
        for (int l=0; l<1000000; l++)
        {
                /* Returns 1 is the word is in dict. */
                int found = aspell_speller_check(speller, word, -1);
                // printf("Found the word: %d\n", found);

                const AspellWordList *list = aspell_speller_suggest(speller, word, -1);
                AspellStringEnumeration *elem = aspell_word_list_elements(list);
                unsigned int size = aspell_word_list_size(list);

                const char *aword = NULL;
                while ((aword = aspell_string_enumeration_next(elem)) != NULL)
                {
                        // printf("Spell suggesion: %s\n", aword);
                        k++;
                }
                delete_aspell_string_enumeration(elem);

                if (0 == l%20000)
                {
                        printf("Loop count= %d spell suggests= %lu\n", l, k);
                        malloc_stats();
                }
        }

        delete_aspell_speller(speller);
        delete_aspell_config(config);
}

Debugged in opencog/link-grammar#1373

@kevina kevina added the bug label Oct 19, 2023
@kevina kevina added this to the 0.60.9 milestone Oct 20, 2023
@kevina
Copy link
Member

kevina commented Oct 20, 2023

Thanks for the test case and sorry for the long delay. I can confirm that this is the same issue as #600 and is fixed by #601.

@kevina kevina mentioned this issue Oct 20, 2023
kevina added a commit that referenced this issue Oct 21, 2023
@kevina kevina modified the milestones: 0.60.9, 0.60.8.1 Nov 2, 2023
@kevina kevina closed this as completed in 75d0aa3 Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants