Commit 155b0bb
authored
Fix memory leak with CLIENT LIST/KILL duplicate filters (#2362)
With #1401, we introduced additional filters to CLIENT LIST/KILL
subcommand. The intended behavior was to pick the last value of the
filter. However, we introduced memory leak for all the preceding
filters.
Before this change:
```
> CLIENT LIST IP 127.0.0.1 IP 127.0.0.1
id=4 addr=127.0.0.1:37866 laddr=127.0.0.1:6379 fd=10 name= age=0 idle=0 flags=N capa= db=0 sub=0 psub=0 ssub=0 multi=-1 watch=0 qbuf=0 qbuf-free=0 argv-mem=21 multi-mem=0 rbs=16384 rbp=16384 obl=0 oll=0 omem=0 tot-mem=16989 events=r cmd=client|list user=default redir=-1 resp=2 lib-name= lib-ver= tot-net-in=49 tot-net-out=0 tot-cmds=0
```
Leak:
```
Direct leak of 11 byte(s) in 1 object(s) allocated from:
#0 0x7f2901aa557d in malloc (/lib64/libasan.so.4+0xd857d)
#1 0x76db76 in ztrymalloc_usable_internal /workplace/harkrisp/valkey/src/zmalloc.c:156
#2 0x76db76 in zmalloc_usable /workplace/harkrisp/valkey/src/zmalloc.c:200
#3 0x4c4121 in _sdsnewlen.constprop.230 /workplace/harkrisp/valkey/src/sds.c:113
#4 0x4dc456 in parseClientFiltersOrReply.constprop.63 /workplace/harkrisp/valkey/src/networking.c:4264
#5 0x4bb9f7 in clientListCommand /workplace/harkrisp/valkey/src/networking.c:4600
#6 0x641159 in call /workplace/harkrisp/valkey/src/server.c:3772
#7 0x6431a6 in processCommand /workplace/harkrisp/valkey/src/server.c:4434
#8 0x4bfa9b in processCommandAndResetClient /workplace/harkrisp/valkey/src/networking.c:3571
#9 0x4bfa9b in processInputBuffer /workplace/harkrisp/valkey/src/networking.c:3702
#10 0x4bffa3 in readQueryFromClient /workplace/harkrisp/valkey/src/networking.c:3812
#11 0x481015 in callHandler /workplace/harkrisp/valkey/src/connhelpers.h:79
#12 0x481015 in connSocketEventHandler.lto_priv.394 /workplace/harkrisp/valkey/src/socket.c:301
#13 0x7d3fb3 in aeProcessEvents /workplace/harkrisp/valkey/src/ae.c:486
#14 0x7d4d44 in aeMain /workplace/harkrisp/valkey/src/ae.c:543
#15 0x453925 in main /workplace/harkrisp/valkey/src/server.c:7319
#16 0x7f2900cd7139 in __libc_start_main (/lib64/libc.so.6+0x21139)
```
Note: For filter ID / NOT-ID we group all the option and perform
filtering whereas for remaining filters we only pick the last filter
option.
---------
Signed-off-by: Harkrishn Patro <[email protected]>1 parent 5bbbc6b commit 155b0bb
2 files changed
+154
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4577 | 4577 | | |
4578 | 4578 | | |
4579 | 4579 | | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
| 4583 | + | |
4580 | 4584 | | |
4581 | 4585 | | |
4582 | 4586 | | |
4583 | 4587 | | |
4584 | 4588 | | |
4585 | 4589 | | |
4586 | 4590 | | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
4587 | 4595 | | |
4588 | 4596 | | |
4589 | 4597 | | |
| |||
4597 | 4605 | | |
4598 | 4606 | | |
4599 | 4607 | | |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
4600 | 4612 | | |
4601 | 4613 | | |
4602 | 4614 | | |
4603 | 4615 | | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
| 4619 | + | |
4604 | 4620 | | |
4605 | 4621 | | |
4606 | 4622 | | |
4607 | 4623 | | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
4608 | 4628 | | |
4609 | 4629 | | |
4610 | 4630 | | |
4611 | 4631 | | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
4612 | 4636 | | |
4613 | 4637 | | |
4614 | 4638 | | |
| |||
4635 | 4659 | | |
4636 | 4660 | | |
4637 | 4661 | | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
4638 | 4666 | | |
4639 | 4667 | | |
4640 | 4668 | | |
4641 | 4669 | | |
4642 | 4670 | | |
4643 | 4671 | | |
4644 | 4672 | | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
4645 | 4677 | | |
4646 | 4678 | | |
4647 | 4679 | | |
4648 | 4680 | | |
4649 | 4681 | | |
4650 | 4682 | | |
4651 | 4683 | | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
4652 | 4688 | | |
4653 | 4689 | | |
4654 | 4690 | | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
4655 | 4695 | | |
4656 | 4696 | | |
4657 | 4697 | | |
| |||
5016 | 5056 | | |
5017 | 5057 | | |
5018 | 5058 | | |
| 5059 | + | |
5019 | 5060 | | |
5020 | 5061 | | |
5021 | 5062 | | |
| |||
0 commit comments