Deutsch English Français Italiano |
<v53sl1$35qt7$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feed.opticnetworks.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams <thiago.adams@gmail.com> Newsgroups: comp.lang.c Subject: Fixing a sample from K&R book using cake static analyser Date: Fri, 21 Jun 2024 09:45:21 -0300 Organization: A noiseless patient Spider Lines: 45 Message-ID: <v53sl1$35qt7$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 21 Jun 2024 14:45:21 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2cdbec3a7eec436d78b7441de9bc1ff1"; logging-data="3337127"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ucmIgpLNpEjMaj9sywE0oMhrb6XazkIQ=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ZpzXHhqffFB65tFkoXdMXr5NSxI= Content-Language: en-GB Bytes: 2033 In this video ( https://youtu.be/ZZCKPKzNUCQ ) I show step by step how removing warnings will fix a memory leak. Page 145, The C programming Language 2 Edition /* install: put (name, defn) in hashtab */ struct nlist *install(char *name, char *defn) { struct nlist *np; unsigned hashval; if ((np = lookup(name)) == NULL) { /* not found */ np = (struct nlist *) malloc(sizeof(*np)); if (np == NULL || (np->name = strdup(name)) == NULL) return NULL; hashval = hash(name); np->next = hashtab[hashval]; hashtab[hashval] = np; } else /* already there */ free((void *) np->defn); /* free previous defn */ if ((np->defn = strdup(defn)) == NULL) return NULL; return np; } The concepts used are - ownership transfer - nullable pointers Concepts are described here http://thradams.com/cake/ownership.html To see the sample and play with it: http://thradams.com/cake/playground.html Select "find the bug" and "bug #7 K & R"