Re: Possible memory leak?

From: Daniel A. Koepke (dkoepke@circlemud.org)
Date: 12/01/01


On Sat, 1 Dec 2001, The Arrow wrote:

> The solution I made, was to do it in create_entry() (db.c), where I put
> an else at the end of the if, and in there free the name if it's not
> NULL.

How about:

   int create_entry(char *name)
   {
     .
     .
     .
     } else if ((pos = get_ptable_by_name(name)) == -1) {  /* new name */
       i = ++top_of_ptable + 1;

       RECREATE(player_table, struct player_index_element, i);
       pos = top_of_p_table;

       /*
        * Since the name is the same and already allocated for deleted
        * players, we only CREATE and set for new names.
        */
       CREATE(player_table[pos].name, char, strlen(name) + 1);

       /* copy lowercase equivalent of name to table field */
       for (i = 0; (player_table[pos].name[i] = LOWER(name[i])); i++)
         /* Nothing */ ;
    }

    return (pos);
  }

Can someone verify that this fixes a problem and doesn't introduce any new
ones?

-dak

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/24/03 PDT