# Memory Leak?

Ian Macintosh (ian@iman.internet.co.nz)
Mon, 15 May 1995 21:07:19 PDT

- Messages sorted by:[ date ][ thread ][ subject ][ author ]

    I was browsing through the LambdaMOO 1.7.8p4 source, and I seem to have
    come across a memory leak.

    Would somebody be kind enough to double check and let me know if it is
    indeed a memory leak or not?

    in tasks.c, the function do_command_task(), the last 'else' section, and
    I quote the pertinant code:

            else {
                Var result, args;
    ...[snip]
                args = parse_into_wordlist(command);
    ...[snip]
                free_var(result);
    	}

    *should* have the last section read:

                free_var(result);
    	    free_var(args);
    	}

    I checked to see if the lack of free_var(args) would in fact cause a
    memory leak, and it does seem to.  Past life regression therapy reveals:

    The function parse_into_wordlist() has:

        args = new_list(argc);

    and the function new_list() has:

        new.v.list = (Var *) mymalloc((size + 1) * sizeof (Var), M_LIST);

    which is never released, unless you call free_var(args).

    There is one further syntactical type patch I would do:

    in tasks.c, the function do_command_task():

            if (!parse_command(command, &pi))
                return 0;

    should really read:

            if (!parse_command(command, &pi))
            {
                free_pi(&pi, 0);
                return 0;
            }

    I backtracked this one, and it would *not* actually cause a memory leak,
    even though it might be better to call the free_pi() in any case.  Future
    patches/modifications might turn it into a memory leak.

    Regards,

    Ian.

    +--------------------------------------------------------------------+
    | Ian Macintosh         | P.O. Box 24-036 | Anything really worth    |
    | General Manager       | Royal Oak       | doing, is worth doing    |
    | Sytek New Zealand Ltd | Auckland 1      | badly.     - Duncan Shaw |
    +--------------------------------------------------------------------+