diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-07-02 21:01:43 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2002-07-02 21:01:43 +0800 |
commit | 562677712b03d169f51840c79690111b235ec862 (patch) | |
tree | 28b0c9bd3bf6ff7c819045459639d69890c389e7 | |
parent | 038f26837cc4efacf5798361e0d229516ba119ff (diff) | |
download | pttbbs-562677712b03d169f51840c79690111b235ec862.tar pttbbs-562677712b03d169f51840c79690111b235ec862.tar.gz pttbbs-562677712b03d169f51840c79690111b235ec862.tar.bz2 pttbbs-562677712b03d169f51840c79690111b235ec862.tar.lz pttbbs-562677712b03d169f51840c79690111b235ec862.tar.xz pttbbs-562677712b03d169f51840c79690111b235ec862.tar.zst pttbbs-562677712b03d169f51840c79690111b235ec862.zip |
fix memory bug
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@400 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/friend.c | 30 | ||||
-rw-r--r-- | mbbsd/indict.c | 6 | ||||
-rw-r--r-- | mbbsd/name.c | 4 | ||||
-rw-r--r-- | mbbsd/talk.c | 4 |
4 files changed, 25 insertions, 19 deletions
diff --git a/mbbsd/friend.c b/mbbsd/friend.c index 4a3f636c..c24f6240 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.7 2002/06/19 13:27:16 lwms Exp $ */ +/* $Id: friend.c,v 1.8 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -184,24 +184,22 @@ static void friend_append(int type, int count) { setfriendfile(sfile, j); - fp = fopen(sfile, "r"); - while (fgets(buf, 80, fp) && count <= friend_max[type]) - { - char the_id[15]; - - sscanf(buf, "%s", the_id); - if (!belong(fpath, the_id)) - { - if ((fp1 = fopen(fpath, "a"))) - { - flock(fileno(fp1), LOCK_EX); - fputs(buf, fp1); - flock(fileno(fp1), LOCK_UN); - fclose(fp1); + if( (fp = fopen(sfile, "r")) != NULL ){ + while (fgets(buf, 80, fp) && count <= friend_max[type]){ + char the_id[15]; + + sscanf(buf, "%s", the_id); + if (!belong(fpath, the_id)){ + if ((fp1 = fopen(fpath, "a"))){ + flock(fileno(fp1), LOCK_EX); + fputs(buf, fp1); + flock(fileno(fp1), LOCK_UN); + fclose(fp1); + } } } + fclose(fp); } - fclose(fp); } void friend_delete(char *uident, int type) { diff --git a/mbbsd/indict.c b/mbbsd/indict.c index 8861b320..ca44033a 100644 --- a/mbbsd/indict.c +++ b/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: indict.c,v 1.4 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -8,6 +8,10 @@ static void addword(char word[]) char buf[150],temp[150],a[3]; FILE *fp = fopen(database,"r+"); + if( fp == NULL ){ + vmsg("database error"); + return ; + } fgets(buf,130,fp); fseek(fp,0,2); if(HAVE_PERM(PERM_LOGINOK)) { diff --git a/mbbsd/name.c b/mbbsd/name.c index f2a0f704..af32daa5 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.8 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: name.c,v 1.9 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -497,6 +497,8 @@ int gnc_completeone(char *data, int start, int end, int (*permission)(int), char* (*getname)(int)) { int i, count, at; + if( start < 0 || end < 0 ) + return -1; for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) if( permission(i) ){ at = i; diff --git a/mbbsd/talk.c b/mbbsd/talk.c index e0c5fa92..780c0244 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.73 2002/07/02 02:12:56 in2 Exp $ */ +/* $Id: talk.c,v 1.74 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -441,6 +441,8 @@ void my_write2(void) water_t *tw; unsigned char mode0; + if( swater[0] == NULL ) + return; wmofo = 0; currstat0 = currstat; c0 = currutmp->chatid[0]; |