diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-10-21 15:29:59 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-10-21 22:30:39 +0000 |
commit | a6d81effbc23acce59fd88b8f828fe8c753eeb0d (patch) | |
tree | 0bf5ccc7dd8aca8697d50785d88ba0fe704b9f81 | |
parent | 7f6a4926d2f6a135960146041c29802db616aa63 (diff) |
Clean up file handle management.
The main reason fclose() could fail is if the file is open for writing,
not all the buffered data has been written out at the time fclose() was
called, and the attempt to write it out fails. In any case, the file
handle is no longer valid after fclose() completes, whether the close
succeeds or not, so there's no reason to keep it around.
There's no reason to check whether it's null in a loop called in code
where it's not null to start with and where it's not set to null in the
loop.
This should fix CID 1374111.
Change-Id: Ib8067a17731b41d6b184a5a415addc2ecaa7c00c
Reviewed-on: https://code.wireshark.org/review/18359
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | plugins/profinet/packet-dcerpc-pn-io.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/plugins/profinet/packet-dcerpc-pn-io.c b/plugins/profinet/packet-dcerpc-pn-io.c index 859c381ab9..f00c758965 100644 --- a/plugins/profinet/packet-dcerpc-pn-io.c +++ b/plugins/profinet/packet-dcerpc-pn-io.c @@ -8774,7 +8774,7 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset, if(fp != NULL) { /* ---- Get VendorID & DeviceID ---- */ - while(fp != NULL && fgets(puffer, MAX_LINE_LENGTH, fp) != NULL) { + while(fgets(puffer, MAX_LINE_LENGTH, fp) != NULL) { /* ----- VendorID ------ */ if((strstr(puffer, vendorIdStr)) != NULL) { memset (convertStr, 0, sizeof(*convertStr)); @@ -8802,10 +8802,8 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset, } } - if(fclose(fp) == 0) { - /* File close sucessfull */ - fp = NULL; - } + fclose(fp); + fp = NULL; if(vendorMatch && deviceMatch) { break; /* Found correct GSD-file! -> Break the searchloop */ @@ -9007,10 +9005,8 @@ dissect_ExpectedSubmoduleBlockReq_block(tvbuff_t *tvb, int offset, } } - if (fclose(fp) == 0) { - /* File close successful */ - fp = NULL; - } + fclose(fp); + fp = NULL; } switch (u16SubmoduleProperties & 0x03) { |