From owner-freebsd-questions@FreeBSD.ORG Wed May 17 18:37:16 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AC50D16B813 for ; Wed, 17 May 2006 18:37:16 +0000 (UTC) (envelope-from wbs@infowest.com) Received: from tozar.infowest.com (tozar.out.smtp.infowest.com [204.17.177.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0C9A543D7C for ; Wed, 17 May 2006 18:36:54 +0000 (GMT) (envelope-from wbs@infowest.com) Received: from alora.infowest.com (alora.client.smtp.infowest.com [204.17.177.61]) by tozar.infowest.com (Postfix) with ESMTP id 1F5ED247093; Wed, 17 May 2006 12:36:48 -0600 (MDT) Received: from [127.0.0.1] (71-213-95-210.slkc.qwest.net [71.213.95.210]) by alora.infowest.com (Postfix) with ESMTP id CAB0E1E3315; Wed, 17 May 2006 12:36:47 -0600 (MDT) Message-ID: <446B6D38.4070105@infowest.com> Date: Wed, 17 May 2006 12:36:40 -0600 From: Lorin Lund User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andy Greenwood References: <3ee9ca710605171109i57ae4064x702216a1619d6c41@mail.gmail.com> In-Reply-To: <3ee9ca710605171109i57ae4064x702216a1619d6c41@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions Subject: Re: C coding question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 May 2006 18:37:19 -0000 Andy Greenwood wrote: > I am helping someone work on porting some code to Freebsd, and the > code below works on Linux, but not on FreeBSD (compiles, but gives > Segmentation Fault: 11). I'm not sure where the problem is, and any > pointers would be much appreciated. > > /* Check if we must stop */ > if(tf_stat_file != NULL) > { > tf_stat = fopen(tf_stat_file, "r"); > if (tf_stat != NULL) > { > /* Get state */ > stat_state=fgetc(tf_stat); > > /* Torrentflux asked to shutdown the torrent */ > if (stat_state == '0') > { > mustDie = 1; > } > } > fclose(tf_stat); > } > _______________________________________________ I think I would move the fclose( tf_stat) up a line. No need to close a file that failed to open. The fclose( ) acting on a NULL pointer might be your error.