File: pr99774-1.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (61 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Reproducer for report from -Wanalyzer-malloc-leak
   Reduced from
     https://git.qemu.org/?p=qemu.git;a=blob;f=subprojects/libvhost-user/libvhost-user.c;h=fab7ca17ee1fb27bcfc338527d1aeb9f923aade5;hb=HEAD#l1184
   which is licensed under GNU GPLv2 or later. */

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint64_t;
typedef unsigned long uint64_t;
typedef __SIZE_TYPE__ size_t;

extern void *calloc(size_t __nmemb, size_t __size)
  __attribute__((__nothrow__, __leaf__))
  __attribute__((__malloc__))
  __attribute__((__alloc_size__(1, 2)))
  __attribute__((__warn_unused_result__));

typedef struct VuDescStateSplit {
  uint8_t inflight;
  uint64_t counter;
} VuDescStateSplit;

typedef struct VuVirtqInflight {
  uint16_t desc_num;
  VuDescStateSplit desc[];
} VuVirtqInflight;

typedef struct VuVirtqInflightDesc {
  uint16_t index;
  uint64_t counter;
} VuVirtqInflightDesc;

typedef struct VuVirtq {
  VuVirtqInflight *inflight;
  VuVirtqInflightDesc *resubmit_list;
  uint16_t resubmit_num;
  uint64_t counter;
  int inuse;
} VuVirtq;

int vu_check_queue_inflights(VuVirtq *vq) {
  int i = 0;

  if (vq->inuse) {
    vq->resubmit_list = (VuVirtqInflightDesc *) calloc(vq->inuse, sizeof(VuVirtqInflightDesc));
    if (!vq->resubmit_list) {
      return -1;
    }

    for (i = 0; i < vq->inflight->desc_num; i++) {
      if (vq->inflight->desc[i].inflight) {
        vq->resubmit_list[vq->resubmit_num].index = i; /* { dg-bogus "leak" } */
        vq->resubmit_list[vq->resubmit_num].counter =
            vq->inflight->desc[i].counter;
        vq->resubmit_num++;
      }
    }
  }

  return 0;
}