annotate tests/test-posix_spawn_file_actions_adddup2.c @ 40224:5d9b82ca550a

tests: Free allocated memory. Reported by <deltatau@protonmail.com> via Assaf Gordon. * tests/test-astrxfrm.c (main): Free allocated memory. * tests/test-bitset.c (compare, check_attributes): Free allocated bitsets. * tests/test-filenamecat.c (main): Free allocated memory. * tests/test-freadahead.c (main): Free allocated memory and close stdin. * tests/test-freadptr.c (main): Likewise. * tests/test-freadptr2.c (main): Free allocated memory. * tests/test-freadseek.c (main): Likewise. * tests/test-gc-arcfour.c (main): Close allocated context. * tests/test-gc-arctwo.c (main): Likewise. * tests/test-gc-des.c (main): Close all allocated contexts. * tests/test-pipe-filter-gi1.c (main): Free allocated memory. * tests/test-pipe-filter-ii1.c (main): Likewise. * tests/test-posix_spawn_file_actions_addchdir.c (main): Destroy the allocated file actions. * tests/test-posix_spawn_file_actions_addclose.c (main): Likewise. * tests/test-posix_spawn_file_actions_adddup2.c (main): Likewise. * tests/test-posix_spawn_file_actions_addopen.c (main): Likewise. * tests/test-sameacls.c (main): Free allocated memory and ACLs. * tests/test-strfmon_l.c (main): Free allocated locales. * tests/test-striconveh.c (main): Free allocated iconv_t objects. * tests/uniconv/test-u8-conv-to-enc.c (main): Free allocated memory. * tests/uniconv/test-u16-conv-to-enc.c (main): Likewise. * tests/uniconv/test-u32-conv-to-enc.c (main): Likewise. * tests/unistr/test-chr.h (main): Free input32. * tests/unistr/test-strchr.h (test_strchr): Likewise.
author Bruno Haible <bruno@clisp.org>
date Sun, 10 Mar 2019 14:05:09 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test posix_spawn_file_actions_adddup2() function.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2011-2019 Free Software Foundation, Inc.
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <spawn.h>
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "signature.h"
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 SIGNATURE_CHECK (posix_spawn_file_actions_adddup2, int,
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 (posix_spawn_file_actions_t *, int, int));
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <errno.h>
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
26 #include <limits.h>
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
27 #include <unistd.h>
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "macros.h"
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
31 /* Return a file descriptor that is too big to use.
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
32 Prefer the smallest such fd, except use OPEN_MAX if it is defined
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
33 and is greater than getdtablesize (), as that's how OS X works. */
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
34 static int
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
35 big_fd (void)
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
36 {
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
37 int fd = getdtablesize ();
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
38 #ifdef OPEN_MAX
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
39 if (fd < OPEN_MAX)
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
40 fd = OPEN_MAX;
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
41 #endif
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
42 return fd;
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
43 }
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
44
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 int
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 main (void)
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 {
17418
88b6febaed97 tests: port large-fd POSIX spawn tests to OS X
Paul Eggert <eggert@cs.ucla.edu>
parents: 17373
diff changeset
48 int bad_fd = big_fd ();
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 posix_spawn_file_actions_t actions;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 ASSERT (posix_spawn_file_actions_init (&actions) == 0);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* Test behaviour for invalid file descriptors. */
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 errno = 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 ASSERT (posix_spawn_file_actions_adddup2 (&actions, -1, 2) == EBADF);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 errno = 0;
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
60 ASSERT (posix_spawn_file_actions_adddup2 (&actions, bad_fd, 2) == EBADF);
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 errno = 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, -1) == EBADF);
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 {
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 errno = 0;
17373
160b88fd4691 tests: don't assume getdtablesize () <= 10000000
Paul Eggert <eggert@cs.ucla.edu>
parents: 17249
diff changeset
68 ASSERT (posix_spawn_file_actions_adddup2 (&actions, 2, bad_fd) == EBADF);
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 }
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
40224
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
71 posix_spawn_file_actions_destroy (&actions);
5d9b82ca550a tests: Free allocated memory.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
72
15724
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 return 0;
f8e83fa8f473 Tests for module 'posix_spawn_file_actions_adddup2'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 }