Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 5a20b10

Browse files
committed
Allocate dummy memory in lt entries to catch leaks
1 parent 9bec07c commit 5a20b10

File tree

2 files changed

+126
-112
lines changed

2 files changed

+126
-112
lines changed

src/bcmlt/main/bcmlt_ltable_entry.c

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,89 @@
55
* entry allocation and free, entry commit and get entry info.
66
*/
77
/*
8-
* Copyright: (c) 2018 Broadcom. All Rights Reserved. "Broadcom" refers to
8+
* Copyright: (c) 2018 Broadcom. All Rights Reserved. "Broadcom" refers to
99
* Broadcom Limited and/or its subsidiaries.
10-
*
10+
*
1111
* Broadcom Switch Software License
12-
*
13-
* This license governs the use of the accompanying Broadcom software. Your
14-
* use of the software indicates your acceptance of the terms and conditions
15-
* of this license. If you do not agree to the terms and conditions of this
12+
*
13+
* This license governs the use of the accompanying Broadcom software. Your
14+
* use of the software indicates your acceptance of the terms and conditions
15+
* of this license. If you do not agree to the terms and conditions of this
1616
* license, do not use the software.
1717
* 1. Definitions
1818
* "Licensor" means any person or entity that distributes its Work.
19-
* "Software" means the original work of authorship made available under
19+
* "Software" means the original work of authorship made available under
2020
* this license.
21-
* "Work" means the Software and any additions to or derivative works of
21+
* "Work" means the Software and any additions to or derivative works of
2222
* the Software that are made available under this license.
23-
* The terms "reproduce," "reproduction," "derivative works," and
23+
* The terms "reproduce," "reproduction," "derivative works," and
2424
* "distribution" have the meaning as provided under U.S. copyright law.
25-
* Works, including the Software, are "made available" under this license
26-
* by including in or with the Work either (a) a copyright notice
27-
* referencing the applicability of this license to the Work, or (b) a copy
25+
* Works, including the Software, are "made available" under this license
26+
* by including in or with the Work either (a) a copyright notice
27+
* referencing the applicability of this license to the Work, or (b) a copy
2828
* of this license.
2929
* 2. Grant of Copyright License
30-
* Subject to the terms and conditions of this license, each Licensor
31-
* grants to you a perpetual, worldwide, non-exclusive, and royalty-free
32-
* copyright license to reproduce, prepare derivative works of, publicly
33-
* display, publicly perform, sublicense and distribute its Work and any
30+
* Subject to the terms and conditions of this license, each Licensor
31+
* grants to you a perpetual, worldwide, non-exclusive, and royalty-free
32+
* copyright license to reproduce, prepare derivative works of, publicly
33+
* display, publicly perform, sublicense and distribute its Work and any
3434
* resulting derivative works in any form.
3535
* 3. Grant of Patent License
36-
* Subject to the terms and conditions of this license, each Licensor
37-
* grants to you a perpetual, worldwide, non-exclusive, and royalty-free
38-
* patent license to make, have made, use, offer to sell, sell, import, and
39-
* otherwise transfer its Work, in whole or in part. This patent license
40-
* applies only to the patent claims licensable by Licensor that would be
41-
* infringed by Licensor's Work (or portion thereof) individually and
36+
* Subject to the terms and conditions of this license, each Licensor
37+
* grants to you a perpetual, worldwide, non-exclusive, and royalty-free
38+
* patent license to make, have made, use, offer to sell, sell, import, and
39+
* otherwise transfer its Work, in whole or in part. This patent license
40+
* applies only to the patent claims licensable by Licensor that would be
41+
* infringed by Licensor's Work (or portion thereof) individually and
4242
* excluding any combinations with any other materials or technology.
43-
* If you institute patent litigation against any Licensor (including a
44-
* cross-claim or counterclaim in a lawsuit) to enforce any patents that
45-
* you allege are infringed by any Work, then your patent license from such
46-
* Licensor to the Work shall terminate as of the date such litigation is
43+
* If you institute patent litigation against any Licensor (including a
44+
* cross-claim or counterclaim in a lawsuit) to enforce any patents that
45+
* you allege are infringed by any Work, then your patent license from such
46+
* Licensor to the Work shall terminate as of the date such litigation is
4747
* filed.
4848
* 4. Redistribution
49-
* You may reproduce or distribute the Work only if (a) you do so under
50-
* this License, (b) you include a complete copy of this License with your
51-
* distribution, and (c) you retain without modification any copyright,
49+
* You may reproduce or distribute the Work only if (a) you do so under
50+
* this License, (b) you include a complete copy of this License with your
51+
* distribution, and (c) you retain without modification any copyright,
5252
* patent, trademark, or attribution notices that are present in the Work.
5353
* 5. Derivative Works
54-
* You may specify that additional or different terms apply to the use,
55-
* reproduction, and distribution of your derivative works of the Work
56-
* ("Your Terms") only if (a) Your Terms provide that the limitations of
57-
* Section 7 apply to your derivative works, and (b) you identify the
58-
* specific derivative works that are subject to Your Terms.
59-
* Notwithstanding Your Terms, this license (including the redistribution
54+
* You may specify that additional or different terms apply to the use,
55+
* reproduction, and distribution of your derivative works of the Work
56+
* ("Your Terms") only if (a) Your Terms provide that the limitations of
57+
* Section 7 apply to your derivative works, and (b) you identify the
58+
* specific derivative works that are subject to Your Terms.
59+
* Notwithstanding Your Terms, this license (including the redistribution
6060
* requirements in Section 4) will continue to apply to the Work itself.
6161
* 6. Trademarks
62-
* This license does not grant any rights to use any Licensor's or its
63-
* affiliates' names, logos, or trademarks, except as necessary to
62+
* This license does not grant any rights to use any Licensor's or its
63+
* affiliates' names, logos, or trademarks, except as necessary to
6464
* reproduce the notices described in this license.
6565
* 7. Limitations
66-
* Platform. The Work and any derivative works thereof may only be used, or
66+
* Platform. The Work and any derivative works thereof may only be used, or
6767
* intended for use, with a Broadcom switch integrated circuit.
68-
* No Reverse Engineering. You will not use the Work to disassemble,
69-
* reverse engineer, decompile, or attempt to ascertain the underlying
68+
* No Reverse Engineering. You will not use the Work to disassemble,
69+
* reverse engineer, decompile, or attempt to ascertain the underlying
7070
* technology of a Broadcom switch integrated circuit.
7171
* 8. Termination
72-
* If you violate any term of this license, then your rights under this
73-
* license (including the license grants of Sections 2 and 3) will
72+
* If you violate any term of this license, then your rights under this
73+
* license (including the license grants of Sections 2 and 3) will
7474
* terminate immediately.
7575
* 9. Disclaimer of Warranty
76-
* THE WORK IS PROVIDED "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY
77-
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF
78-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR
79-
* NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER
80-
* THIS LICENSE. SOME STATES' CONSUMER LAWS DO NOT ALLOW EXCLUSION OF AN
76+
* THE WORK IS PROVIDED "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY
77+
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF
78+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR
79+
* NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER
80+
* THIS LICENSE. SOME STATES' CONSUMER LAWS DO NOT ALLOW EXCLUSION OF AN
8181
* IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU.
8282
* 10. Limitation of Liability
83-
* EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL
84-
* THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE
85-
* SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT,
86-
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
87-
* OR RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK
88-
* (INCLUDING BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION,
89-
* LOST PROFITS OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER
90-
* COMMERCIAL DAMAGES OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF
83+
* EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL
84+
* THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE
85+
* SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT,
86+
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
87+
* OR RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK
88+
* (INCLUDING BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION,
89+
* LOST PROFITS OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER
90+
* COMMERCIAL DAMAGES OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF
9191
* THE POSSIBILITY OF SUCH DAMAGES.
9292
*/
9393

@@ -180,7 +180,7 @@ int bcmlt_entry_allocate(int unit,
180180
if (!table_name || !entry_hdl) {
181181
LOG_VERBOSE(BSL_LOG_MODULE,
182182
(BSL_META_U(unit,
183-
"Table name and entry handle shouln't"\
183+
"Table name and entry handle shouldn't"\
184184
" be NULL\n")));
185185
SHR_RETURN_VAL_EXIT(SHR_E_PARAM);
186186
}
@@ -199,6 +199,13 @@ int bcmlt_entry_allocate(int unit,
199199
table_attr->name);
200200
SHR_NULL_CHECK(entry, SHR_E_MEMORY);
201201
entry->db_hdl = hdl;
202+
#ifdef __SANITIZE_ADDRESS__ || __has_feature(address_sanitizer)
203+
entry->dummy = malloc(1);
204+
#endif
205+
206+
#ifdef __SANITIZE_ADDRESS__ || __has_feature(address_sanitizer)
207+
asdf
208+
#endif
202209
/* Clean the fields array */
203210
if (fld_array_hdl) {
204211
sal_memset(entry->fld_arr, 0, sizeof(void *) * (table_attr->max_fid+1));
@@ -277,6 +284,10 @@ int bcmlt_entry_free(bcmlt_entry_handle_t entry_hdl)
277284
SHR_RETURN_VAL_EXIT(SHR_E_BUSY);
278285
}
279286

287+
#ifdef __SANITIZE_ADDRESS__ || __has_feature(address_sanitizer)
288+
free(entry->dummy);
289+
#endif
290+
280291
SHR_IF_ERR_EXIT(bcmlt_hdl_free(entry_hdl));
281292

282293
SHR_IF_ERR_EXIT(bcmtrm_entry_free(entry));

0 commit comments

Comments
 (0)