Commit 53acf950 authored by David Byers's avatar David Byers

Memory management

        Free everything on exit
        The server should now exit with zero allocated strings and
        zero allocated blocks.

Test cases
        Added a few test cases for improved coverage and recently
        fixed bugs.
parent bfa4c83a
1999-05-21 David Byers <davby@ida.liu.se>
* doc/lyskomd.texi: Merged lyskomdb.texi into this document.
* src/server/server-config.c: Unassign the lockfile name.
* doc/Makefile.am (info_TEXINFOS): Removed deleted files.
(EXTRA_DIST): Removed deleted files from EXTRA_DIST.
* src/server/conf-file.c (unassign_string): New function.
* src/server/conf-file.h (parameter): Added a free function.
* src/server/simple-cache.c (free_all_cache): Free the
small_conf_arr.
* src/server/ramkomd.c (dump_exit_statistics): Moved remaining
frees from main to here.
1999-05-20 David Byers <davby@ida.liu.se>
* src/server/testsuite/config/unix.exp: You can now supply
MEMTRACE, ATTACH and EFENCE algorithms on the runtest command
line.
* src/server/testsuite/Makefile.am (EXTRA_DIST): Added new leak
tests to EXTRA_DIST.
Eliminated memory leaks in aux-item definition parser
* src/server/aux-items.c (free_aux_item_definitions): Free each
individual aux item definition. Another memory leak down the
drain.
* src/server/aux-item-def-parse.y: Free the string of an ID
parameter when we see one. Another memory leak bites the dust.
* src/server/aux-items.c (aux_item_definition_cache_regexp): Plug
a really minor (constant size) memory leak.
* src/server/aux-item-def-parse.y: Use string_free to free stuff
allocated with s_crea_c_str.
* src/server/aux-items.c (aux_item_trigger_link_item): Use
string_free to free string allocated with s_crea_c_str.
(free_aux_item_definitions): Same here.
1999-05-19 David Byers <davby@ida.liu.se>
* src/server/prot-a-parse.c (prot_a_parse_aux_item_list): Clear
the dummy aux item after parsing it. Memory leak plugged.
* src/server/memory.c (clear_aux_item): New function.
(free_aux_item_list): Use it.
* src/server/prot-a-parse.c (prot_a_parse_num_list): Handle
truncation so protocol errors during truncation will not break the
server.
(prot_a_hunt_nl): Same here.
(prot_a_parse_aux_item_list): Same here.
* src/server/prot-a.c (prot_a_init): Initialize
array_parse_parsed_length
* src/server/internal-connections.c (init_connection): Initialize
array_parse_parsed_length
* src/server/connections.c (free_parsed): Initialize
array_parse_parsed_length.
* src/server/connections.h (Connection): Added
array_parse_parsed_length
* src/server/fncdef.txt: Truncate strings in set_client_version to
client_data_len.
* src/server/ramkomd.c (main): Free aux-item definitions on exit.
* src/server/aux-items.c (free_aux_item_definitions): New function
to free all data associated with aux-item defs.
* src/server/ramkomd.c (main): Free aux-item definition.
1999-05-18 David Byers <davby@ida.liu.se>
* src/server/prot-a-parse.c (prot_a_parse_aux_item_flags): Handle
variable-length bitfields.
* src/server/memory.c (init_aux_item_flags): New function.
* src/server/prot-a-parse.c (prot_a_parse_priv_bits): Handle
variable-length bitfields.
(prot_a_parse_membership_type): Same here.
(prot_a_parse_conf_type): Same here.
* src/server/memory.c (init_membership_type): New function.
* doc/Protocol-A.texi (set-client-version): Added list of known
clients.
* ChangeLog.1: Inserted doc/LOGG
* doc/LOGG: Added to ChangeLog.1
* src/server/conference.c (set_supervisor): Use
is_strictly_supervisor instead of is_supervisor.
1999-05-21 Per Cederqvist <ceder@gratia>
Lock the database file with an explicit lock file.
......
......@@ -1053,3 +1053,85 @@ Wed Apr 18 00:08:22 1990 Per Cederqvist (ceder at lage)
* Ny funktion i services: query_unread_mail. (Se m 230)
Wed Apr 18 00:08:22 1990 Per Cederqvist (ceder at lage)
Det SIST SKRIVNA hamnar F\RST I FILEN /Aronsson.
Loggfil d{r man skriver vad man g|r. Det {r b{ttre att du skriver
lite
{n inte alls (mest riktat till mig sj{lv...). /lw 900402
----------------------------------------------------------------------
3 juni 1991 Aronsson
Uppdaterat prot-A.txt och i denna inkluderat prot-A.bnf. Satt
prot-A.bnf till att vara en symbolisk l{nk till txt-filen.
14 oktober 1990 Aronsson was here
Lagt hit nedanst}ende filer. Originalen beh}ller jag hemma hos mig.
prot-A.txt Spec protokoll A. Textdelen. Svensk font.
prot-A.bnf Spec protokoll A. Koddelen. Engelsk font.
version Hantering av {ndringsf|rslag och versioner.
1990-04-17 /ceder
Tog bort den felaktiga definitionen av typen Connection ur kom-types.h. Den
riktiga finns i server/server.h.
Flyttade definitioner av Persons, Marks, String och Map till kom-types.h.
B|rjade anv{nda M-X Add-change-log-entry i st{llet.
900407 /lw
Det h{r {r c. Allts} b|r active_connection vara en pekare! (har {ndrat)
Flyttade smalloc ("s{ker" malloc) till cache.c.
Nu sparar ldb.c {ven texts-f{ltet i person-structen...
1990-04-04 /ceder
[ndrade i Person-structen: Tog bort created_texts. La till
first_text, last_text och texts (en lista med globala textnummer de globala
textnummer som personen har skapat.)
active_connection (server.h) {r index i arrayen connections (connections.c).
Skapade filen doc/security-levels.txt d{r det anges vad de olika priv-bitarna
inneb{r.
900404 /lw
[ndrade ldb:s felhantering. Nu finns den! Fortfarande inte speciellt
snygg, men n}got b{ttre {n tidigare. Returnerar intern felkod i
ldb_errno och filhandtag till felande filen i ldb_errfileno.
1990-04-02 /ceder
Fr}n och med nu anv{nder vi ISO-standard f|r datum. (:-)
kom-types.h: Tog bort flags och lade till user_area i Person-structen.
900402 /lw
Vi flyttade om filerna. Under ldb ligger nu i princip endast ldb.c och
ldb.h. Under client ligger de filer som {r specifika f|r klienten och
under server ligger de server-specifika filerna. doc-directoryt
inneh}ller dokumentationen f|r det vi h}ller p} med.
Direkt under 2kom ligger f|r n{rvarande allt som {r gemensamt f|r
s}v{l klient som server. Det {r types.h och kom-types.h (varf|r {r
det uppdelat i tv} filer?) samt services.h som tidigare hette
atomic.h.
Jag har f|rresten tagit bort parametern connection som alla
funktioner i atomic.h hade. Fr}n klientens synvinkel finns inte
den parametern och det verkar f}nigt att ha den i servern. Om man
har samma parameter till samtliga funktioner tycker jag det {r
ganska vettigt att i st{llet anv{nda en global variabel.
This diff is collapsed.
%{
/*
* $Id: aux-item-def-parse.y,v 1.6 1999/05/18 13:06:45 byers Exp $
* $Id: aux-item-def-parse.y,v 1.7 1999/05/21 11:36:37 byers Exp $
* Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -91,6 +91,7 @@
#include "lyskomd.h"
#include "debug.h"
#include "log.h"
#include "string-malloc.h"
BUGDECL;
......@@ -316,10 +317,10 @@ assign : ID '=' value ';'
tmp = s_crea_c_str($1);
aux_item_def_error_line = @1.first_line;
yyerror("invalid field name: %s", tmp);
free(tmp);
string_free(tmp);
}
if ($3.type == STRING)
if ($3.type == STRING || $3.type == ID)
{
s_clear(&($3).val.str);
$3.val.str = EMPTY_STRING;
......@@ -446,7 +447,7 @@ short aux_item_def_check_trigger(const char *check_name,
tmp_string = s_crea_c_str(function_name);
trigger = aux_item_find_trigger(tmp_string);
sfree(tmp_string);
string_free(tmp_string);
if (trigger == NULL)
{
......@@ -555,7 +556,7 @@ short aux_item_def_check_validate(const char *check_name,
{
tmp_string = s_crea_c_str(data);
validator = aux_item_find_validator(tmp_string);
sfree(tmp_string);
string_free(tmp_string);
if (validator == NULL)
{
......
/*
* $Id: aux-items.c,v 1.12 1999/05/18 13:06:46 byers Exp $
* $Id: aux-items.c,v 1.13 1999/05/21 11:36:39 byers Exp $
* Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -57,6 +57,7 @@
#include "admin.h"
#include "param.h"
#include "server-time.h"
#include "string-malloc.h"
#define AUX_ADJUST_FLAG(flg) item->flags.flg = (def->clear_flags.flg)?0:((def->set_flags.flg)?1:item->flags.flg)
......@@ -474,7 +475,10 @@ aux_item_definition_cache_regexp(Aux_item_definition *def,
def->name);
if (def->validators[ix].v.re.cached_re_buf)
sfree(def->validators[ix].v.re.cached_re_buf);
if (def->validators[ix].v.re.regexp)
string_free(def->validators[ix].v.re.regexp);
def->validators[ix].v.re.cached_re_buf = NULL;
def->validators[ix].v.re.regexp = NULL;
return;
}
}
......@@ -483,7 +487,6 @@ void
initialize_aux_items(char *aux_def_file)
{
unsigned long i;
Aux_item_definition *def;
/* Set up precompiled items */
......@@ -497,16 +500,59 @@ initialize_aux_items(char *aux_def_file)
/* Read definitions from configuration file */
parse_aux_item_definitions(aux_def_file);
}
def = aux_item_definition_list;
void
free_aux_item_definitions(void)
{
unsigned long i;
Aux_item_definition *def;
Aux_item_definition *tmp;
def = aux_item_definition_list;
while (def != NULL)
{
/* FIXME: If we have validators, go through and cache their
FIXME: regexps, where appropriate */
def = def->next;
string_free(def->name);
for (i = 0; i < def->num_validators; i++)
{
if (def->validators[i].type == AUX_VALIDATE_REGEXP)
{
if (def->validators[i].v.re.regexp != NULL)
string_free(def->validators[i].v.re.regexp);
if (def->validators[i].v.re.cached_re_buf != NULL)
sfree(def->validators[i].v.re.cached_re_buf);
}
}
if (def->validators != NULL)
{
sfree(def->validators);
def->validators = NULL;
def->num_validators = 0;
}
if (def->add_triggers != NULL)
{
sfree(def->add_triggers);
def->add_triggers = NULL;
def->num_add_triggers = 0;
}
if (def->delete_triggers != NULL)
{
sfree(def->delete_triggers);
def->delete_triggers = NULL;
def->num_delete_triggers = 0;
}
if (def->undelete_triggers != NULL)
{
sfree(def->undelete_triggers);
def->undelete_triggers = NULL;
def->num_undelete_triggers = 0;
}
tmp = def->next;
sfree(def);
def = tmp;
}
aux_item_definition_list = NULL;
}
......@@ -912,6 +958,8 @@ static Bool aux_item_validate(Aux_item_validation_data validation_data)
kom_log("Failed to cache regexp \"%s\". Rejecting all \"%s\" items",
def->validators[i].v.re.regexp,
def->name);
sfree(def->validators[i].v.re.regexp);
def->validators[i].v.re.regexp = NULL;
def->validators[i].type = AUX_VALIDATE_REJECT;
kom_errno = KOM_ILL_AUX;
return FALSE;
......@@ -1978,13 +2026,15 @@ void aux_item_trigger_link_item(Aux_item_trigger_data *data)
* The string is given by the current item
*/
tmp_str = s_crea_c_str(data->item->data);
nread = sscanf(tmp_str,
"%c %lu %lu",
&type_char,
&target_item_tag,
&target_object_no);
sfree(tmp_str);
string_free(tmp_str);
if (nread != 3)
return;
......
/*
* $Id: aux-items.h,v 1.9 1999/05/18 13:06:47 byers Exp $
* $Id: aux-items.h,v 1.10 1999/05/21 11:36:39 byers Exp $
* Copyright (C) 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -117,7 +117,7 @@ typedef struct
} Aux_item_trigger_mapping;
struct Aux_item_definition_s {
const char * name;
char * name;
unsigned long tag;
Aux_item_flags clear_flags;
Aux_item_flags set_flags;
......@@ -318,12 +318,12 @@ Success system_check_add_aux_item_list(Info *info,
Aux_item_list *list,
Pers_no creator);
void
initialize_aux_items(char *);
void initialize_aux_items(char *);
void free_aux_item_definitions(void);
void
aux_item_definition_add(Aux_item_definition *);
void aux_item_definition_add(Aux_item_definition *);
/* Parser function from aux-item-def.y. */
void
parse_aux_item_definitions(char *file);
extern void parse_aux_item_definitions(char *file);
/*
* $Id: conf-file.c,v 1.14 1999/05/12 13:25:01 byers Exp $
* $Id: conf-file.c,v 1.15 1999/05/21 11:36:40 byers Exp $
* Copyright (C) 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +33,7 @@
static const char *
rcsid = "$Id: conf-file.c,v 1.14 1999/05/12 13:25:01 byers Exp $";
rcsid = "$Id: conf-file.c,v 1.15 1999/05/21 11:36:40 byers Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -345,3 +345,14 @@ assign_bool(const char *val,
return OK;
}
void
unassign_string(const struct parameter *par)
{
if (*(char**)par->value != NULL)
{
sfree(*(char**)par->value);
*(char**)par->value = NULL;
}
}
/*
* $Id: conf-file.h,v 1.4 1999/05/12 13:25:02 byers Exp $
* $Id: conf-file.h,v 1.5 1999/05/21 11:36:42 byers Exp $
* Copyright (C) 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -40,6 +40,7 @@ union param_value {
struct parameter {
const char *name;
Success (*assigner)(const char *val, const struct parameter *par);
void (*freer)(const struct parameter *par);
int min_assignments;
int max_assignments; /* -1 == eternity */
const char *default_val; /* String, as read from the config file. */
......@@ -55,4 +56,6 @@ extern Success assign_ulong (const char *val, const struct parameter *par);
extern Success assign_string (const char *val, const struct parameter *par);
extern Success assign_bool (const char *val, const struct parameter *par);
extern void unassign_string(const struct parameter *par);
#endif
/*
* $Id: conference.c,v 0.48 1999/05/18 13:06:49 byers Exp $
* $Id: conference.c,v 0.49 1999/05/21 11:36:43 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -35,7 +35,7 @@
static const char *
rcsid = "$Id: conference.c,v 0.48 1999/05/18 13:06:49 byers Exp $";
rcsid = "$Id: conference.c,v 0.49 1999/05/21 11:36:43 byers Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -955,7 +955,7 @@ set_supervisor( Conf_no conf_no,
if (new_super != 0)
CHK_EXIST(new_super, FAILURE);
if ( !is_supervisor(conf_no, conf_c, ACTPERS, ACT_P) &&
if ( !is_strictly_supervisor(conf_no, conf_c, ACTPERS, ACT_P) &&
!ENA(wheel, 8) &&
!ENA(admin, 6) )
{
......
/*
* $Id: connections.c,v 0.60 1999/05/18 13:06:50 byers Exp $
* $Id: connections.c,v 0.61 1999/05/21 11:36:44 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -36,7 +36,7 @@
#endif
static const char *
rcsid = "$Id: connections.c,v 0.60 1999/05/18 13:06:50 byers Exp $";
rcsid = "$Id: connections.c,v 0.61 1999/05/21 11:36:44 byers Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -303,6 +303,7 @@ free_parsed(Connection *client)
client->parse_pos = 0;
client->fnc_parse_pos = 0;
client->array_parse_index = 0;
client->array_parse_parsed_length = 0;
client->array_parse_pos = 0;
client->struct_parse_pos = 0;
client->string_parse_pos = 0;
......
/*
* $Id: connections.h,v 0.42 1999/05/18 13:06:51 byers Exp $
* $Id: connections.h,v 0.43 1999/05/21 11:36:45 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -23,7 +23,7 @@
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* $Id: connections.h,v 0.42 1999/05/18 13:06:51 byers Exp $
* $Id: connections.h,v 0.43 1999/05/21 11:36:45 byers Exp $
*
* connections.h -- The top level of the communication packet.
*
......@@ -71,6 +71,7 @@ typedef struct connection {
int fnc_parse_pos;
int array_parse_pos;
int array_parse_index;
int array_parse_parsed_length;
int struct_parse_pos;
int string_parse_pos;
int hunt_parse_pos;
......
#
# $Id: fncdef.txt,v 0.40 1999/05/18 13:06:52 byers Exp $
# $Id: fncdef.txt,v 0.41 1999/05/21 11:36:46 byers Exp $
# Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997
# Lysator Academic Computer Association.
#
......@@ -23,7 +23,7 @@
#
# Please mail bug reports to bug-lyskom@lysator.liu.se.
#
# $Id: fncdef.txt,v 0.40 1999/05/18 13:06:52 byers Exp $
# $Id: fncdef.txt,v 0.41 1999/05/21 11:36:46 byers Exp $
#
# This file is used to describe the functions in services.c. All
# functions that are reachable from the clients are listed here, together
......@@ -124,7 +124,7 @@
#
67 success lookup_person c_string (param.conf_name_len) : conf_no_list
68 success lookup_conf c_string (param.conf_name_len) : conf_no_list
69 success set_client_version c_string (param.conf_name_len) c_string (param.conf_name_len)
69 success set_client_version c_string (param.client_data_len) c_string (param.client_data_len)
70 success get_client_name num : string
71 success get_client_version num : string
72 success mark_text num num
......
/*
* $Id: internal-connections.c,v 0.37 1999/05/18 13:06:53 byers Exp $
* $Id: internal-connections.c,v 0.38 1999/05/21 11:36:47 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -35,7 +35,7 @@
static const char *
rcsid = "$Id: internal-connections.c,v 0.37 1999/05/18 13:06:53 byers Exp $";
rcsid = "$Id: internal-connections.c,v 0.38 1999/05/21 11:36:47 byers Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -106,6 +106,7 @@ init_connection(Connection *conn)
conn->fnc_parse_pos = 0;
conn->array_parse_pos = 0;
conn->array_parse_index = 0;
conn->array_parse_parsed_length = 0;
conn->struct_parse_pos = 0;
conn->string_parse_pos = 0;
conn->hunt_parse_pos = 0;
......
/*
* $Id: kom-memory.h,v 1.10 1999/05/12 13:25:11 byers Exp $
* $Id: kom-memory.h,v 1.11 1999/05/21 11:36:48 byers Exp $
* Copyright (C) 1991, 1993, 1994, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -23,7 +23,7 @@
* Please mail bug reports to bug-lyskom@lysator.liu.se.
*/
/*
* $Id: kom-memory.h,v 1.10 1999/05/12 13:25:11 byers Exp $
* $Id: kom-memory.h,v 1.11 1999/05/21 11:36:48 byers Exp $
*
* The time has come to get some order into this mess.
*
......@@ -63,6 +63,9 @@ extern void init_mark_list (Mark_list *ml);
/* Member_list */
extern void init_member_list (Member_list *ml);
/* Membership type */
extern void init_membership_type(Membership_type *m);
/* Membership */
extern void init_membership(Membership *m);
......@@ -116,6 +119,8 @@ extern void free_aux_item_list (Aux_item_list *list);
extern void init_aux_item_list (Aux_item_list *list);
extern void init_aux_item_link(Aux_item_link *dest);
extern void init_aux_item_flags(Aux_item_flags *dest);
extern void clear_aux_item(Aux_item *item);
extern void init_aux_item(Aux_item *dest);
extern void copy_aux_item (Aux_item *dest, const Aux_item *src);
......
/*
* $Id: memory.c,v 0.32 1999/05/12 13:25:16 byers Exp $
* $Id: memory.c,v 0.33 1999/05/21 11:36:49 byers Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1996 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,7 +33,7 @@
#endif
static const char *
rcsid = "$Id: memory.c,v 0.32 1999/05/12 13:25:16 byers Exp $";
rcsid = "$Id: memory.c,v 0.33 1999/05/21 11:36:49 byers Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -282,6 +282,19 @@ copy_membership(Membership m)
return res;
}
void
init_membership_type(Membership_type *m)
{
m->invitation = 0;
m->passive = 0;
m->secret = 0;
m->reserved1 = 0;
m->reserved2 = 0;
m->reserved3 = 0;
m->reserved4 = 0;
m->reserved5 = 0;
}
void
init_membership(Membership *m)
{
......@@ -294,14 +307,7 @@ init_membership(Membership *m)
m->added_by = 0;
m->position = 0;
m->added_at = NO_TIME;
m->type.invitation = 0;
m->type.passive = 0;
m->type.secret = 0;
m->type.reserved1 = 0;
m->type.reserved2 = 0;
m->type.reserved3 = 0;
m->type.reserved4 = 0;
m->type.reserved5 = 0;
init_membership_type(&m->type);
}
/* Membership_list */
......@@ -671,7 +677,7 @@ free_aux_item_list(Aux_item_list *list)
if (list->items != NULL)
{
for (i = 0; i < list->length; i++)
s_clear(&list->items[i].data);
clear_aux_item(&list->items[i]);
}
list->length = 0;
sfree(list->items);
......@@ -708,26 +714,40 @@ init_aux_item_link(Aux_item_link *dest)
dest->target_object.text = 0;
}
void
init_aux_item_flags(Aux_item_flags *dest)
{
dest->deleted = 0;
dest->inherit = 0;
dest->secret = 0;
dest->hide_creator = 0;
dest->dont_garb = 0;
dest->reserved3 = 0;
dest->reserved4 = 0;
dest->reserved5 = 0;
}
void
init_aux_item(Aux_item *dest)
{
dest->aux_no = 0;
dest->creator = 0;
dest->sent_at = 0;
dest->flags.deleted = 0;
dest->flags.inherit = 0;
dest->flags.secret = 0;
dest->flags.hide_creator = 0;
dest->flags.dont_garb = 0;
dest->flags.reserved3 = 0;
dest->flags.reserved4 = 0;
dest->flags.reserved5 = 0;
dest->inherit_limit = 0;
dest->tag = 0;
dest->data = EMPTY_STRING;
init_aux_item_flags(&dest->flags);
init_aux_item_link(&dest->linked_item);
}
void
clear_aux_item(Aux_item *item)
{
s_clear(&item->data);
init_aux_item(item);
}