From 562677712b03d169f51840c79690111b235ec862 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 2 Jul 2002 13:01:43 +0000 Subject: fix memory bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@400 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/friend.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'mbbsd/friend.c') 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) { -- cgit v1.2.3