Try to construct a minimal reproducer, and post it here. Someone may
be able to spot the issue. The shorter and simpler you can make your
reproducer, the more likely someone will be able to help.
The program:
// gcc -o program program.c
// program < lines
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int, char **) {
char * line_buf = NULL;
size_t stg_size = 0u;
ssize_t num_read = 0;
size_t line_num = 0;
while (-1 < (num_read = getline(&line_buf, &stg_size, stdin))) {
++line_num;
printf("%s", line_buf);
if (num_read != 53) {
printf("num_read: %ld at line %lu\n", num_read, line_num);
}
pid_t pid = fork();
if (0 == pid) {
exit(0);
}
else if (pid > 0) {
(void) waitpid(pid, NULL, 0);
}
}
return(0);
}
Without the fork/exit/waitpid block of code, it prints the input successfully. With that code included, it goes into an infinite loop printing the first 78 lines of input, Every second pass over the input,the 78th line is garbled.
77 77 77 77 77xx
78 1 1xx
num_read: 30 at line 6433
2 2 2 2 2xx
The input file "lines" is (all lines 52 charactures + \n == 53 characters):
1 1 1 1 1xx
2 2 2 2 2xx
3 3 3 3 3xx
4 4 4 4 4xx
5 5 5 5 5xx
6 6 6 6 6xx
7 7 7 7 7xx
8 8 8 8 8xx
9 9 9 9 9xx
10 10 10 10 10xx
11 11 11 11 11xx
12 12 12 12 12xx
13 13 13 13 13xx
14 14 14 14 14xx
15 15 15 15 15xx
16 16 16 16 16xx
17 17 17 17 17xx
18 18 18 18 18xx
19 19 19 19 19xx
20 20 20 20 20xx
21 21 21 21 21xx
22 22 22 22 22xx
23 23 23 23 23xx
24 24 24 24 24xx
25 25 25 25 25xx
26 26 26 26 26xx
27 27 27 27 27xx
28 28 28 28 28xx
29 29 29 29 29xx
30 30 30 30 30xx
31 31 31 31 31xx
32 32 32 32 32xx
33 33 33 33 33xx
34 34 34 34 34xx
35 35 35 35 35xx
36 36 36 36 36xx
37 37 37 37 37xx
38 38 38 38 38xx
39 39 39 39 39xx
40 40 40 40 40xx
41 41 41 41 41xx
42 42 42 42 42xx
43 43 43 43 43xx
44 44 44 44 44xx
45 45 45 45 45xx
46 46 46 46 46xx
47 47 47 47 47xx
48 48 48 48 48xx
49 49 49 49 49xx
50 50 50 50 50xx
51 51 51 51 51xx
52 52 52 52 52xx
53 53 53 53 53xx
54 54 54 54 54xx
55 55 55 55 55xx
56 56 56 56 56xx
57 57 57 57 57xx
58 58 58 58 58xx
59 59 59 59 59xx
60 60 60 60 60xx
61 61 61 61 61xx
62 62 62 62 62xx
63 63 63 63 63xx
64 64 64 64 64xx
65 65 65 65 65xx
66 66 66 66 66xx
67 67 67 67 67xx
68 68 68 68 68xx
69 69 69 69 69xx
70 70 70 70 70xx
71 71 71 71 71xx
72 72 72 72 72xx
73 73 73 73 73xx
74 74 74 74 74xx
75 75 75 75 75xx
76 76 76 76 76xx
77 77 77 77 77xx
78 78 78 78 78xx
79 79 79 79 79xx
80 80 80 80 80xx
81 81 81 81 81xx
82 82 82 82 82xx
83 83 83 83 83xx
84 84 84 84 84xx
85 85 85 85 85xx
86 86 86 86 86xx
87 87 87 87 87xx
88 88 88 88 88xx
89 89 89 89 89xx
90 90 90 90 90xx
91 91 91 91 91xx
92 92 92 92 92xx
93 93 93 93 93xx
94 94 94 94 94xx
95 95 95 95 95xx
96 96 96 96 96xx
97 97 97 97 97xx
98 98 98 98 98xx
99 99 99 99 99xx
100 100 100 100 100xx
which can be created using this Perl script,
#!/usr/bin/env perl
for ($i=1; $i <= 100; ++$i)
{
printf("%-10d%10d%10d%10d%10dxx\n", $i, $i, $i, $i, $i);
}