Sujet : Re: Joy of this, Joy of that
De : tnp (at) *nospam* invalid.invalid (The Natural Philosopher)
Groupes : comp.os.linux.miscDate : 23. Nov 2024, 12:20:59
Autres entêtes
Organisation : A little, after lunch
Message-ID : <vhsdqr$1m6qu$3@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla Thunderbird
On 23/11/2024 07:09, Charlie Gibbs wrote:
On 2024-11-22, candycanearter07
<candycanearter07@candycanearter07.nomail.afraid> wrote:
Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote at 18:53 this Friday (GMT):
>
On 2024-11-22, The Natural Philosopher <tnp@invalid.invalid> wrote:
>
On 22/11/2024 10:45, Richard Kettlewell wrote:
>
The one place I’ll use a goto (in C) is to branch to unified cleanup
code in an error case, usually using a macro both to emphasize what’s
going on and to stop the error-handling guff from dominating what the
reader sees.
>
+1
GOTO snafu_nuclear_option... :-)
>
All my programs contain a routine called quit_cleanup(); it takes
a single argument, which is either an error message or NULL.
It frees all allocated memory, closes any open files, etc.
(all such variables are global and I initialize them to NULL
or whatever other value is appropriate). Then, if the error
message argument is not NULL, it displays and/or logs the
message and calls exit() with a non-zero argument. If the
error message argument is NULL, it simply calls exit(0).
I can call it from anywhere, and it guarantees an orderly shutdown.
>
Unless you specifically use your own allocation wrapper that adds it to
an internal list, how do you deallocate "all" the allocations you've
done?
I've occasionally considered making a list, but never got around to
implementing such a scheme. So it's the good old-fashioned way -
free each allocation one by one and hope you don't forget one.
Even then, leaks would be unlikely, because I try to close or free
resources as soon as I'm done with them, and the de-allocations
in quit_cleanup() are mostly belt-and-suspenders code.
If you never explicitly allocated memory you can, in C, do a longjmp() back to a stack that implicity frees any local variables.
I dislike the use of malloc and friends in daemons that run forever. Exiting a program cleans up anyway, Its programs where you are repeatedly allocating and deallocating memory that give problems. Usual due to 'unusual' exits that fail to clean up in the normal way.
-- “Puritanism: The haunting fear that someone, somewhere, may be happy.”H.L. Mencken, A Mencken Chrestomathy
Date | Sujet | # | | Auteur |
19 Nov 24 | Joy of this, Joy of that | 806 | | root |
20 Nov 24 |  Re: Joy of this, Joy of that | 4 | | Lawrence D'Oliveiro |
20 Nov 24 |   Re: Joy of this, Joy of that | 3 | | root |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | rbowman |
20 Nov 24 |  Re: Joy of this, Joy of that | 801 | | 186282@ud0s4.net |
20 Nov 24 |   Re: Joy of this, Joy of that | 193 | | Rich |
20 Nov 24 |    Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
21 Nov 24 |    Re: Joy of this, Joy of that | 191 | | 186282@ud0s4.net |
21 Nov 24 |     Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
14 Jan 25 |      Re: Joy of this, Joy of that | 1 | | Bozo User |
21 Nov 24 |     Re: Joy of this, Joy of that | 187 | | The Natural Philosopher |
22 Nov 24 |      Re: Joy of this, Joy of that | 186 | | Don_from_AZ |
22 Nov 24 |       Re: Joy of this, Joy of that | 185 | | Lawrence D'Oliveiro |
23 Nov 24 |        Re: Joy of this, Joy of that | 184 | | 186282@ud0s4.net |
23 Nov 24 |         Re: Joy of this, Joy of that | 5 | | Lawrence D'Oliveiro |
24 Nov 24 |          Re: Joy of this, Joy of that | 4 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
24 Nov 24 |            Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 1 | | rbowman |
23 Nov 24 |         Re: Joy of this, Joy of that | 178 | | The Natural Philosopher |
23 Nov 24 |          Re: Joy of this, Joy of that | 1 | | rbowman |
23 Nov 24 |          Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
24 Nov 24 |          Re: Joy of this, Joy of that | 174 | | 186282@ud0s4.net |
24 Nov 24 |           Re: Joy of this, Joy of that | 1 | | rbowman |
24 Nov 24 |           Re: Joy of this, Joy of that | 172 | | Rich |
24 Nov 24 |            Re: Joy of this, Joy of that | 168 | | The Natural Philosopher |
24 Nov 24 |             Re: Joy of this, Joy of that | 159 | | Rich |
24 Nov 24 |              Re: Joy of this, Joy of that | 158 | | D |
25 Nov 24 |               Re: Joy of this, Joy of that | 157 | | rbowman |
25 Nov 24 |                Re: Joy of this, Joy of that | 156 | | D |
25 Nov 24 |                 Re: Joy of this, Joy of that | 155 | | The Natural Philosopher |
25 Nov 24 |                  Re: Joy of this, Joy of that | 15 | | D |
26 Nov 24 |                   Re: Joy of this, Joy of that | 14 | | rbowman |
26 Nov 24 |                    Re: Joy of this, Joy of that | 1 | | D |
26 Nov 24 |                    Re: Joy of this, Joy of that | 12 | | Pancho |
26 Nov 24 |                     Re: Joy of this, Joy of that | 11 | | Rich |
26 Nov 24 |                      Re: Joy of this, Joy of that | 2 | | Chris Ahlstrom |
27 Nov 24 |                       Re: Joy of this, Joy of that | 1 | | Pancho |
26 Nov 24 |                      Re: Joy of this, Joy of that | 8 | | rbowman |
26 Nov 24 |                       Re: Joy of this, Joy of that | 4 | | D |
27 Nov 24 |                        Re: Joy of this, Joy of that | 1 | | Rich |
27 Nov 24 |                        Re: Joy of this, Joy of that | 2 | | rbowman |
27 Nov 24 |                         Re: Joy of this, Joy of that | 1 | | D |
27 Nov 24 |                       Re: Joy of this, Joy of that | 3 | | The Natural Philosopher |
27 Nov 24 |                        Re: Joy of this, Joy of that | 2 | | rbowman |
28 Nov 24 |                         Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
25 Nov 24 |                  Re: Joy of this, Joy of that | 139 | | Lawrence D'Oliveiro |
27 Nov 24 |                   Re: Joy of this, Joy of that | 138 | | 186282@ud0s4.net |
27 Nov 24 |                    Re: Joy of this, Joy of that | 137 | | Lawrence D'Oliveiro |
28 Nov 24 |                     Re: Joy of this, Joy of that | 136 | | 186282@ud0s4.net |
28 Nov 24 |                      Re: Joy of this, Joy of that | 133 | | rbowman |
28 Nov 24 |                       Re: Joy of this, Joy of that | 132 | | 186282@ud0s4.net |
28 Nov 24 |                        Re: Joy of this, Joy of that | 3 | | rbowman |
29 Nov 24 |                         Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
29 Nov 24 |                          Re: Joy of this, Joy of that | 1 | | rbowman |
28 Nov 24 |                        Re: Joy of this, Joy of that | 128 | | Lawrence D'Oliveiro |
29 Nov 24 |                         Re: Joy of this, Joy of that | 127 | | 186282@ud0s4.net |
29 Nov 24 |                          Re: Joy of this, Joy of that | 116 | | rbowman |
30 Nov 24 |                           Re: Joy of this, Joy of that | 115 | | 186282@ud0s4.net |
30 Nov 24 |                            Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
30 Nov 24 |                            Re: Joy of this, Joy of that | 113 | | rbowman |
30 Nov 24 |                             Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
1 Dec 24 |                              Re: Joy of this, Joy of that | 1 | | Lawrence D'Oliveiro |
1 Dec 24 |                             Re: Joy of this, Joy of that | 110 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 5 | | The Natural Philosopher |
1 Dec 24 |                               Re: Joy of this, Joy of that | 2 | | Rich |
3 Dec 24 |                                Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | D |
2 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
3 Dec 24 |                               Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
1 Dec 24 |                              Re: Joy of this, Joy of that | 102 | | rbowman |
3 Dec 24 |                               Re: Joy of this, Joy of that | 101 | | 186282@ud0s4.net |
3 Dec 24 |                                Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
3 Dec 24 |                                 Re: Joy of this, Joy of that | 1 | | rbowman |
3 Dec 24 |                                Re: Joy of this, Joy of that | 98 | | rbowman |
5 Dec 24 |                                 Re: Joy of this, Joy of that | 97 | | 186282@ud0s4.net |
5 Dec 24 |                                  Re: Joy of this, Joy of that | 92 | | D |
6 Dec 24 |                                   Re: Joy of this, Joy of that | 91 | | 186282@ud0s4.net |
6 Dec 24 |                                    Re: Joy of this, Joy of that | 37 | | rbowman |
6 Dec 24 |                                     Re: Joy of this, Joy of that | 34 | | D |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
7 Dec 24 |                                       Re: Joy of this, Joy of that | 1 | | D |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 17 | | 186282@ud0s4.net |
7 Dec 24 |                                       Re: Joy of this, Joy of that | 16 | | D |
7 Dec 24 |                                        Re: Joy of this, Joy of that | 14 | | Rich |
7 Dec 24 |                                         Re: Joy of this, Joy of that | 13 | | D |
7 Dec 24 |                                          Re: Joy of this, Joy of that | 12 | | Rich |
7 Dec 24 |                                           Re: Joy of this, Joy of that | 10 | | D |
8 Dec 24 |                                            Re: Joy of this, Joy of that | 7 | | Rich |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 5 | | rbowman |
8 Dec 24 |                                              Re: Joy of this, Joy of that | 4 | | Rich |
8 Dec 24 |                                               Re: Joy of this, Joy of that | 2 | | The Natural Philosopher |
9 Dec 24 |                                                Re: Joy of this, Joy of that | 1 | | The Natural Philosopher |
8 Dec 24 |                                               Re: Joy of this, Joy of that | 1 | | rbowman |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 1 | | D |
8 Dec 24 |                                            Re: Joy of this, Joy of that | 2 | | Robert Riches |
8 Dec 24 |                                             Re: Joy of this, Joy of that | 1 | | D |
7 Dec 24 |                                           Re: Joy of this, Joy of that | 1 | | D |
8 Dec 24 |                                        Re: Joy of this, Joy of that | 1 | | 186282@ud0s4.net |
7 Dec 24 |                                      Re: Joy of this, Joy of that | 14 | | D |
7 Dec 24 |                                     Re: Joy of this, Joy of that | 2 | | 186282@ud0s4.net |
6 Dec 24 |                                    Re: Joy of this, Joy of that | 53 | | D |
5 Dec 24 |                                  Re: Joy of this, Joy of that | 4 | | Lawrence D'Oliveiro |
29 Nov 24 |                          Re: Joy of this, Joy of that | 10 | | Lawrence D'Oliveiro |
28 Nov 24 |                      Re: Joy of this, Joy of that | 2 | | Lawrence D'Oliveiro |
25 Nov 24 |             Re: Joy of this, Joy of that | 8 | | vallor |
24 Nov 24 |            Re: Joy of this, Joy of that | 3 | | D |
24 Nov 24 |          Re: Joy of this, Joy of that | 1 | | Rich |
21 Nov 24 |     Re: Joy of this, Joy of that | 1 | | Rich |
20 Nov 24 |   Re: Joy of this, Joy of that | 606 | | John Ames |
20 Nov 24 |   Re: Joy of this, Joy of that | 1 | | rbowman |