Skip to content

Commit 64cfaf8

Browse files
committed
Merge pull request #4986
6eb67b0 autofile: Disallow by-value copies of CAutoFile (Cory Fields) eee030f autofile: don't copy CAutoFile by value (Cory Fields)
2 parents 610a3d3 + 6eb67b0 commit 64cfaf8

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ bool AppInit2(boost::thread_group& threadGroup)
10581058
}
10591059

10601060
boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
1061-
CAutoFile est_filein = CAutoFile(fopen(est_path.string().c_str(), "rb"), SER_DISK, CLIENT_VERSION);
1061+
CAutoFile est_filein(fopen(est_path.string().c_str(), "rb"), SER_DISK, CLIENT_VERSION);
10621062
// Allowed to fail as this file IS missing on first startup.
10631063
if (est_filein)
10641064
mempool.ReadFeeEstimates(est_filein);

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
10821082
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
10831083
{
10841084
// Open history file to append
1085-
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
1085+
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
10861086
if (!fileout)
10871087
return error("WriteBlockToDisk : OpenBlockFile failed");
10881088

@@ -1110,7 +1110,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
11101110
block.SetNull();
11111111

11121112
// Open history file to read
1113-
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
1113+
CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
11141114
if (!filein)
11151115
return error("ReadBlockFromDisk : OpenBlockFile failed");
11161116

@@ -4503,7 +4503,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
45034503
bool CBlockUndo::WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
45044504
{
45054505
// Open history file to append
4506-
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
4506+
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
45074507
if (!fileout)
45084508
return error("CBlockUndo::WriteToDisk : OpenUndoFile failed");
45094509

@@ -4535,7 +4535,7 @@ bool CBlockUndo::WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
45354535
bool CBlockUndo::ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock)
45364536
{
45374537
// Open history file to read
4538-
CAutoFile filein = CAutoFile(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
4538+
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
45394539
if (!filein)
45404540
return error("CBlockUndo::ReadFromDisk : OpenBlockFile failed");
45414541

src/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
19571957
// open temp output file, and associate with CAutoFile
19581958
boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
19591959
FILE *file = fopen(pathTmp.string().c_str(), "wb");
1960-
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
1960+
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
19611961
if (!fileout)
19621962
return error("%s : Failed to open file %s", __func__, pathTmp.string());
19631963

@@ -1982,7 +1982,7 @@ bool CAddrDB::Read(CAddrMan& addr)
19821982
{
19831983
// open input file, and associate with CAutoFile
19841984
FILE *file = fopen(pathAddr.string().c_str(), "rb");
1985-
CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION);
1985+
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
19861986
if (!filein)
19871987
return error("%s : Failed to open file %s", __func__, pathAddr.string());
19881988

src/serialize.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,14 +1154,18 @@ class CDataStream
11541154

11551155

11561156

1157-
/** RAII wrapper for FILE*.
1157+
/** Non-refcounted RAII wrapper for FILE*.
11581158
*
11591159
* Will automatically close the file when it goes out of scope if not null.
11601160
* If you're returning the file pointer, return file.release().
11611161
* If you need to close the file early, use file.fclose() instead of fclose(file).
11621162
*/
11631163
class CAutoFile
11641164
{
1165+
private:
1166+
// Disallow copies
1167+
CAutoFile(const CAutoFile&);
1168+
CAutoFile& operator=(const CAutoFile&);
11651169
protected:
11661170
FILE* file;
11671171
public:

src/test/checkblock_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool read_block(const std::string& filename, CBlock& block)
3535

3636
fseek(fp, 8, SEEK_SET); // skip msgheader/size
3737

38-
CAutoFile filein = CAutoFile(fp, SER_DISK, CLIENT_VERSION);
38+
CAutoFile filein(fp, SER_DISK, CLIENT_VERSION);
3939
if (!filein) return false;
4040

4141
filein >> block;

0 commit comments

Comments
 (0)