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;








-1















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.










share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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











  • @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












  • 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















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.










share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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











  • @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












  • 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








-1








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.










share|improve this question
















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++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.







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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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











  • @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












  • 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





    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











  • 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






  • 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












1 Answer
1






active

oldest

votes


















0














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 ofstream instead of FILE in 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.






share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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 ofstream instead of FILE in 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.






    share|improve this answer



























      0














      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 ofstream instead of FILE in 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.






      share|improve this answer

























        0












        0








        0







        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 ofstream instead of FILE in 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.






        share|improve this answer













        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 ofstream instead of FILE in 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 3:29









        Michael VekslerMichael Veksler

        5,9141824




        5,9141824















            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해