malloc-annotations.c revision 3ea9e33ea25e0c2b12db56418ba3f994eb662c04
1287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc -analyzer-store=region -verify -analyzer-config unix.Malloc:Optimistic=true %s 2287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwelltypedef __typeof(sizeof(int)) size_t; 3287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid *malloc(size_t); 4287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid free(void *); 5287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid *realloc(void *ptr, size_t size); 6287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid *calloc(size_t nmemb, size_t size); 7287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid __attribute((ownership_returns(malloc))) *my_malloc(size_t); 8287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid __attribute((ownership_takes(malloc, 1))) my_free(void *); 9287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid my_freeBoth(void *, void *) 10287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell __attribute((ownership_holds(malloc, 1, 2))); 11287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid __attribute((ownership_returns(malloc, 1))) *my_malloc2(size_t); 12287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid __attribute((ownership_holds(malloc, 1))) my_hold(void *); 13287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 14287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// Duplicate attributes are silly, but not an error. 15287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// Duplicate attribute has no extra effect. 16287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// If two are of different kinds, that is an error and reported as such. 17287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid __attribute((ownership_holds(malloc, 1))) 18287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell__attribute((ownership_holds(malloc, 1))) 19287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell__attribute((ownership_holds(malloc, 3))) my_hold2(void *, void *, void *); 20287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid *my_malloc3(size_t); 21287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid *myglobalpointer; 22287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct stuff { 23287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell void *somefield; 24287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}; 25287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct stuff myglobalstuff; 26287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 27287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f1() { 28287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 29287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // expected-warning{{Potential leak of memory pointed to by}} 30287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 31287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 32287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f2() { 33287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 34287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); 35912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz free(p); // expected-warning{{Attempt to free released memory}} 36287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 37974b6413f4540d73c21c092cc0a62abb6d546e21José Fonseca 38287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f2_realloc_0() { 39287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 40287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell realloc(p,0); 41287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell realloc(p,0); // expected-warning{{Attempt to free released memory}} 42287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 43287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 44287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f2_realloc_1() { 45287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 46912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz int *q = realloc(p,0); // no-warning 47912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz} 48912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz 49912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz// ownership attributes tests 50912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantzvoid naf1() { 51912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz int *p = my_malloc3(12); 52912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz return; // no-warning 53912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz} 54287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 55287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid n2af1() { 56287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc2(12); 57287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // expected-warning{{Potential leak of memory pointed to by}} 58287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 59e16e70610c459721f4344dc6e61a8af1c2ad870dJosé Fonseca 60e16e70610c459721f4344dc6e61a8af1c2ad870dJosé Fonsecavoid af1() { 61287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 62287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // expected-warning{{Potential leak of memory pointed to by}} 639305e93114542632384eb38da08018b4b9d1ab96José Fonseca} 64ffeed5da6e568836867f09f1acb7ce660d091d4aJosé Fonseca 65287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_b() { 66287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 67287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} // expected-warning{{Potential leak of memory pointed to by}} 68287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 69287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_c() { 70287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell myglobalpointer = my_malloc(12); // no-warning 71287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 72287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 73287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_d() { 74287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell struct stuff mystuff; 75287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell mystuff.somefield = my_malloc(12); 76287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} // expected-warning{{Potential leak of memory pointed to by}} 77287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 78287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// Test that we can pass out allocated memory via pointer-to-pointer. 79287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_e(void **pp) { 80287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell *pp = my_malloc(42); // no-warning 81287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 82287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 83287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_f(struct stuff *somestuff) { 84287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell somestuff->somefield = my_malloc(12); // no-warning 85287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 86287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 87287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// Allocating memory for a field via multiple indirections to our arguments is OK. 88287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af1_g(struct stuff **pps) { 89287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell *pps = my_malloc(sizeof(struct stuff)); // no-warning 90287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell (*pps)->somefield = my_malloc(42); // no-warning 91287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 92287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 93287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af2() { 94287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 95287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_free(p); 96287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); // expected-warning{{Attempt to free released memory}} 97287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 98287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 99287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af2b() { 100287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 101287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); 102287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_free(p); // expected-warning{{Attempt to free released memory}} 103287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 104287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 105287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af2c() { 106287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 107287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); 108dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul my_hold(p); // expected-warning{{Attempt to free released memory}} 109dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul} 110dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul 111dce4c368b5536716770e5cabef0321db8537a6d9Brian Paulvoid af2d() { 112dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul int *p = my_malloc(12); 113dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul free(p); 114287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_hold2(0, 0, p); // expected-warning{{Attempt to free released memory}} 115287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 116287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 117287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// No leak if malloc returns null. 118287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af2e() { 119287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 120287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell if (!p) 121287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // no-warning 122287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); // no-warning 123287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 124287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 125287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// This case inflicts a possible double-free. 126287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid af3() { 127287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 128287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_hold(p); 129912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz free(p); // expected-warning{{Attempt to free non-owned memory}} 130912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz} 131287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 132287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellint * af4() { 133287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 134287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_free(p); 135287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return p; // expected-warning{{Use of memory after it is freed}} 136287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 137287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 138287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// This case is (possibly) ok, be conservative 139287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellint * af5() { 140287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = my_malloc(12); 141287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell my_hold(p); 142287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return p; // no-warning 143287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 144e16e70610c459721f4344dc6e61a8af1c2ad870dJosé Fonseca 145287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 146287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 147287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// This case tests that storing malloc'ed memory to a static variable which is 148287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// then returned is not leaked. In the absence of known contracts for functions 149287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// or inter-procedural analysis, this is a conservative answer. 150287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellint *f3() { 151287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell static int *p = 0; 152287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell p = malloc(12); 153287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return p; // no-warning 154912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz} 155912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz 156287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// This case tests that storing malloc'ed memory to a static global variable 157287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// which is then returned is not leaked. In the absence of known contracts for 158287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell// functions or inter-procedural analysis, this is a conservative answer. 159287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstatic int *p_f4 = 0; 160287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellint *f4() { 161287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell p_f4 = malloc(12); 162287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return p_f4; // no-warning 163912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz} 164912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantz 165912ad8874200c0a89bd23663dc0de378f6691140Jakob Bornecrantzint *f5() { 166287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *q = malloc(12); 167287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell q = realloc(q, 20); 168287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return q; // no-warning 169287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 170287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 171287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f6() { 172287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 173287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell if (!p) 174287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // no-warning 175287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell else 176287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(p); 177287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 178287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 179287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f6_realloc() { 180287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *p = malloc(12); 181287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell if (!p) 182287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell return; // no-warning 183287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell else 184287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell realloc(p,0); 185287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 186287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 187287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 188287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellchar *doit2(); 189287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid pr6069() { 190287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell char *buf = doit2(); 191287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(buf); 192b84590994c4261d85485357263146d5e3d8827ebJosé Fonseca} 193287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 194287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid pr6293() { 195287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(0); 196287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 197287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 198287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f7() { 199287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell char *x = (char*) malloc(4); 200287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell free(x); 201287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell x[0] = 'a'; // expected-warning{{Use of memory after it is freed}} 202287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 203287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 204287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid f7_realloc() { 205287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell char *x = (char*) malloc(4); 206287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell realloc(x,0); 207287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell x[0] = 'a'; // expected-warning{{Use of memory after it is freed}} 208287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 209287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 210287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid PR6123() { 211287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell int *x = malloc(11); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}} 212287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell} 213287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 214dce4c368b5536716770e5cabef0321db8537a6d9Brian Paulvoid PR7217() { 215dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul int *buf = malloc(2); // expected-warning{{Cast a region whose size is not a multiple of the destination type size}} 216dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul buf[1] = 'c'; // not crash 217dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul} 218dce4c368b5536716770e5cabef0321db8537a6d9Brian Paul 219dce4c368b5536716770e5cabef0321db8537a6d9Brian Paulvoid mallocCastToVoid() { 220287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell void *p = malloc(2); 221287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const void *cp = p; // not crash 222 free(p); 223} 224 225void mallocCastToFP() { 226 void *p = malloc(2); 227 void (*fp)() = p; // not crash 228 free(p); 229} 230 231// This tests that malloc() buffers are undefined by default 232char mallocGarbage () { 233 char *buf = malloc(2); 234 char result = buf[1]; // expected-warning{{undefined}} 235 free(buf); 236 return result; 237} 238 239// This tests that calloc() buffers need to be freed 240void callocNoFree () { 241 char *buf = calloc(2,2); 242 return; // expected-warning{{Potential leak of memory pointed to by}} 243} 244 245// These test that calloc() buffers are zeroed by default 246char callocZeroesGood () { 247 char *buf = calloc(2,2); 248 char result = buf[3]; // no-warning 249 if (buf[1] == 0) { 250 free(buf); 251 } 252 return result; // no-warning 253} 254 255char callocZeroesBad () { 256 char *buf = calloc(2,2); 257 char result = buf[3]; // no-warning 258 if (buf[1] != 0) { 259 free(buf); // expected-warning{{never executed}} 260 } 261 return result; // expected-warning{{Potential leak of memory pointed to by}} 262} 263 264void testMultipleFreeAnnotations() { 265 int *p = malloc(12); 266 int *q = malloc(12); 267 my_freeBoth(p, q); 268} 269 270