fopen can't open file after a few minutes [closed]using custom deleter with unique_ptrC++ program runs slow in VS2008fopen - can't write more than 16K?fopen fails invisibly when creating files in system drive (C:)Writing multiple files slows down after x secondsQt can't load any image in Release configIs fwrite faster than WriteFile in windows?When does the value of file descriptor become “-1”?Issue opening JPEG file with libjpeg: possible fopen failure?Debug Assertion Failed in fwrite.cppfopen / ofstream::open fail when creating a BMP file
How to know whether to write accidentals as sharps or flats?
How did Avada Kedavra get its name?
Approach sick days in feedback meeting
What things do I only get a limited opportunity to take photos of?
New Site Design!
How long would it take for sucrose to undergo hydrolysis in boiling water?
How can Caller ID be faked?
Bullying by school - Submitted PhD thesis but not allowed to proceed to viva until change to new supervisor
Does an African-American baby born in Youngstown, Ohio have a higher infant mortality rate than a baby born in Iran?
Will users know a CardView is clickable
My parents claim they cannot pay for my college education; what are my options?
Can I give my friend the sour dough "throw away" as a starter to their sourdough starter?
How do credit card companies know what type of business I'm paying for?
Do items with curse of vanishing disappear from shulker boxes?
Co-worker is now managing my team, does this mean that I'm being demoted?
Someone who is granted access to information but not expected to read it
What made the Ancient One do this in Endgame?
How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?
Why not make one big cpu core?
How to search for Android apps without ads?
Why is Skinner so awkward in Hot Fuzz?
What does the output current rating from an H-Bridge's datasheet really mean?
Print the phrase "And she said, 'But that's his.'" using only the alphabet
Can Dive Down protect a creature against Pacifism?
fopen can't open file after a few minutes [closed]
using custom deleter with unique_ptrC++ program runs slow in VS2008fopen - can't write more than 16K?fopen fails invisibly when creating files in system drive (C:)Writing multiple files slows down after x secondsQt can't load any image in Release configIs fwrite faster than WriteFile in windows?When does the value of file descriptor become “-1”?Issue opening JPEG file with libjpeg: possible fopen failure?Debug Assertion Failed in fwrite.cppfopen / ofstream::open fail when creating a BMP file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to write some logs in file.
This is my Code:
FILE *writefile = fopen((Dir + FileName).data(), "at");
if (writefile)
fprintf(writefile, log.data());
fclose(writefile);
It surely works the first time when I try to write.
This code is executed in networking system, but it is executed in no connection status.
So, it keeps writing log "Try Connct" in every sec.
This is the image what I want to write
I can see these log on my console.
In image, I try to write log over 11:10:00.
But in File, it was not written until 11:06:00.
I try to debug my code,
This is the image in debugging
Why this happens?
---Addition---
I try to print error. So, I used perror.
I got Error : Too many open files.
But Why? Obviously I closed file, as you can see in my code.
c++
closed as off-topic by Max Vollmer, user4581301, Baum mit Augen♦ Mar 25 at 23:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Max Vollmer, user4581301, Baum mit Augen
|
show 5 more comments
I want to write some logs in file.
This is my Code:
FILE *writefile = fopen((Dir + FileName).data(), "at");
if (writefile)
fprintf(writefile, log.data());
fclose(writefile);
It surely works the first time when I try to write.
This code is executed in networking system, but it is executed in no connection status.
So, it keeps writing log "Try Connct" in every sec.
This is the image what I want to write
I can see these log on my console.
In image, I try to write log over 11:10:00.
But in File, it was not written until 11:06:00.
I try to debug my code,
This is the image in debugging
Why this happens?
---Addition---
I try to print error. So, I used perror.
I got Error : Too many open files.
But Why? Obviously I closed file, as you can see in my code.
c++
closed as off-topic by Max Vollmer, user4581301, Baum mit Augen♦ Mar 25 at 23:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Max Vollmer, user4581301, Baum mit Augen
1
I don't know whyfopen()is failing, but you can get a hint about why it fails by checking the value oferrnoimmediately afterfopen()returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)
– Jeremy Friesner
Mar 25 at 2:36
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
Maybe one ofDirorFileNamehave changed. Maybe your antivirus is getting in the way.
– drescherjm
Mar 25 at 2:51
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
1
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06
|
show 5 more comments
I want to write some logs in file.
This is my Code:
FILE *writefile = fopen((Dir + FileName).data(), "at");
if (writefile)
fprintf(writefile, log.data());
fclose(writefile);
It surely works the first time when I try to write.
This code is executed in networking system, but it is executed in no connection status.
So, it keeps writing log "Try Connct" in every sec.
This is the image what I want to write
I can see these log on my console.
In image, I try to write log over 11:10:00.
But in File, it was not written until 11:06:00.
I try to debug my code,
This is the image in debugging
Why this happens?
---Addition---
I try to print error. So, I used perror.
I got Error : Too many open files.
But Why? Obviously I closed file, as you can see in my code.
c++
I want to write some logs in file.
This is my Code:
FILE *writefile = fopen((Dir + FileName).data(), "at");
if (writefile)
fprintf(writefile, log.data());
fclose(writefile);
It surely works the first time when I try to write.
This code is executed in networking system, but it is executed in no connection status.
So, it keeps writing log "Try Connct" in every sec.
This is the image what I want to write
I can see these log on my console.
In image, I try to write log over 11:10:00.
But in File, it was not written until 11:06:00.
I try to debug my code,
This is the image in debugging
Why this happens?
---Addition---
I try to print error. So, I used perror.
I got Error : Too many open files.
But Why? Obviously I closed file, as you can see in my code.
c++
c++
edited Mar 25 at 3:01
Retalia K
asked Mar 25 at 2:30
Retalia KRetalia K
279
279
closed as off-topic by Max Vollmer, user4581301, Baum mit Augen♦ Mar 25 at 23:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Max Vollmer, user4581301, Baum mit Augen
closed as off-topic by Max Vollmer, user4581301, Baum mit Augen♦ Mar 25 at 23:08
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Max Vollmer, user4581301, Baum mit Augen
1
I don't know whyfopen()is failing, but you can get a hint about why it fails by checking the value oferrnoimmediately afterfopen()returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)
– Jeremy Friesner
Mar 25 at 2:36
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
Maybe one ofDirorFileNamehave changed. Maybe your antivirus is getting in the way.
– drescherjm
Mar 25 at 2:51
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
1
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06
|
show 5 more comments
1
I don't know whyfopen()is failing, but you can get a hint about why it fails by checking the value oferrnoimmediately afterfopen()returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)
– Jeremy Friesner
Mar 25 at 2:36
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
Maybe one ofDirorFileNamehave changed. Maybe your antivirus is getting in the way.
– drescherjm
Mar 25 at 2:51
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
1
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06
1
1
I don't know why
fopen() is failing, but you can get a hint about why it fails by checking the value of errno immediately after fopen() returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)– Jeremy Friesner
Mar 25 at 2:36
I don't know why
fopen() is failing, but you can get a hint about why it fails by checking the value of errno immediately after fopen() returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)– Jeremy Friesner
Mar 25 at 2:36
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
Maybe one of
Dir or FileName have changed. Maybe your antivirus is getting in the way.– drescherjm
Mar 25 at 2:51
Maybe one of
Dir or FileName have changed. Maybe your antivirus is getting in the way.– drescherjm
Mar 25 at 2:51
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
1
1
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06
|
show 5 more comments
1 Answer
1
active
oldest
votes
You have a resource leak in your program. There are too many open/dup/fopen/stream::open/pipe/connect/accept/socket calls without a matching close/fclose/~stream/stream::close.
In the case of FILE leak, you can avoid it by one of:
- use
ofstreaminstead ofFILEin all your code. It will automatically close the file when it gets out of scope. - use unique_ptr of FILE with a custom deleter. This will close the file automatically, when it gets out of scope.
Unfortunately there is no easy way to find this leak. The best way is to avoid it from the beginning, by using RAII all the way with std::stream, std::unique_ptr, and boost asio. Since the code didn't follow this rule, the only way out is to search for fopen (and others) through the code, and make it use RAII, possibly with unique_ptr.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have a resource leak in your program. There are too many open/dup/fopen/stream::open/pipe/connect/accept/socket calls without a matching close/fclose/~stream/stream::close.
In the case of FILE leak, you can avoid it by one of:
- use
ofstreaminstead ofFILEin all your code. It will automatically close the file when it gets out of scope. - use unique_ptr of FILE with a custom deleter. This will close the file automatically, when it gets out of scope.
Unfortunately there is no easy way to find this leak. The best way is to avoid it from the beginning, by using RAII all the way with std::stream, std::unique_ptr, and boost asio. Since the code didn't follow this rule, the only way out is to search for fopen (and others) through the code, and make it use RAII, possibly with unique_ptr.
add a comment |
You have a resource leak in your program. There are too many open/dup/fopen/stream::open/pipe/connect/accept/socket calls without a matching close/fclose/~stream/stream::close.
In the case of FILE leak, you can avoid it by one of:
- use
ofstreaminstead ofFILEin all your code. It will automatically close the file when it gets out of scope. - use unique_ptr of FILE with a custom deleter. This will close the file automatically, when it gets out of scope.
Unfortunately there is no easy way to find this leak. The best way is to avoid it from the beginning, by using RAII all the way with std::stream, std::unique_ptr, and boost asio. Since the code didn't follow this rule, the only way out is to search for fopen (and others) through the code, and make it use RAII, possibly with unique_ptr.
add a comment |
You have a resource leak in your program. There are too many open/dup/fopen/stream::open/pipe/connect/accept/socket calls without a matching close/fclose/~stream/stream::close.
In the case of FILE leak, you can avoid it by one of:
- use
ofstreaminstead ofFILEin all your code. It will automatically close the file when it gets out of scope. - use unique_ptr of FILE with a custom deleter. This will close the file automatically, when it gets out of scope.
Unfortunately there is no easy way to find this leak. The best way is to avoid it from the beginning, by using RAII all the way with std::stream, std::unique_ptr, and boost asio. Since the code didn't follow this rule, the only way out is to search for fopen (and others) through the code, and make it use RAII, possibly with unique_ptr.
You have a resource leak in your program. There are too many open/dup/fopen/stream::open/pipe/connect/accept/socket calls without a matching close/fclose/~stream/stream::close.
In the case of FILE leak, you can avoid it by one of:
- use
ofstreaminstead ofFILEin all your code. It will automatically close the file when it gets out of scope. - use unique_ptr of FILE with a custom deleter. This will close the file automatically, when it gets out of scope.
Unfortunately there is no easy way to find this leak. The best way is to avoid it from the beginning, by using RAII all the way with std::stream, std::unique_ptr, and boost asio. Since the code didn't follow this rule, the only way out is to search for fopen (and others) through the code, and make it use RAII, possibly with unique_ptr.
answered Mar 25 at 3:29
Michael VekslerMichael Veksler
5,9141824
5,9141824
add a comment |
add a comment |
1
I don't know why
fopen()is failing, but you can get a hint about why it fails by checking the value oferrnoimmediately afterfopen()returns NULL (or, perhaps more conveniently, by calling perror("fopen") at that point, to see what error-message gets printed)– Jeremy Friesner
Mar 25 at 2:36
@JeremyFriesner Okay, I'll try to print error. Thanks
– Retalia K
Mar 25 at 2:42
Maybe one of
DirorFileNamehave changed. Maybe your antivirus is getting in the way.– drescherjm
Mar 25 at 2:51
I got Error : Too many open files. But Why? Obviously I closed file As you can see in my code.
– Retalia K
Mar 25 at 3:00
1
Your error might just be a symptom of an underlying problem elsewhere in your code. Try to create a minimal reproducible example, as right now we can only poke in the dark and do guess work. Also please don't screenshot error messages, debug information or code. Include any textual information as text, not as image. Thanks!
– Max Vollmer
Mar 25 at 3:06