Bug 1027317 - cups-browsed leaks a lot of memory
cups-browsed leaks a lot of memory
Product: Fedora
Classification: Fedora
Component: cups-filters (Show other bugs)
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jaromír Končický
Fedora Extras Quality Assurance
: Patch
Depends On:
  Show dependency treegraph
Reported: 2013-11-06 09:38 EST by Zdenek Kabelac
Modified: 2014-07-01 18:55 EDT (History)
4 users (show)

See Also:
Fixed In Version: cups-filters-1.0.41-4.fc20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2013-11-23 22:54:32 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Valgrind log of cups-browsed (745.78 KB, text/plain)
2013-11-06 09:38 EST, Zdenek Kabelac
no flags Details
diff between 1.0.40 and 1.0.41 (24.26 KB, patch)
2013-11-12 10:04 EST, Jaromír Končický
no flags Details | Diff
patch (537 bytes, patch)
2013-11-12 11:30 EST, Jaromír Končický
no flags Details | Diff
New valgrind trace (252.46 KB, text/plain)
2013-11-12 13:41 EST, Zdenek Kabelac
no flags Details
new (hopefully final) patch (1.31 KB, patch)
2013-11-14 04:26 EST, Jaromír Končický
no flags Details | Diff
Valgring trace with fixed memleak (682.05 KB, text/plain)
2013-11-14 06:44 EST, Zdenek Kabelac
no flags Details

  None (edit)
Description Zdenek Kabelac 2013-11-06 09:38:12 EST
Created attachment 820421 [details]
Valgrind log  of cups-browsed

Description of problem:

Looking for some other problems in my system I've noticed large memory leaks in cups-browsed.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:

Actual results:

Expected results:

Additional info:
Comment 1 Jaromír Končický 2013-11-07 04:38:03 EST
Could you please provide more information about how to reproduce this Valgrind log? It would make it easier for me.
Especially how you run cups-browsed (with valgrind) and how it is exited (the program exits itself or you use some signal). Thanks.
Comment 2 Zdenek Kabelac 2013-11-07 05:25:11 EST
To get the valgrind trace use:

valgrind --track-fds=yes --read-var-info=yes --leak-check=full --track-origins=yes --num-callers=40 --show-reachable=yes  --time-stamp=yes /usr/sbin/cups-browsed  -d

Be sure you have as much -debuginfo packages for all needed libs - mainly cups-filters & cups, glib2, glibc.

Focus on 'lost' elements in trace  like i.e.:

==00:00:04:00.739 16973== 4,098 bytes in 69 blocks are definitely lost in loss record 335 of 349

==00:00:04:00.731 16973== 656 (64 direct, 592 indirect) bytes in 1 blocks are definitely lost in loss record 297 of 349

==00:00:04:00.741 16973== 502,016 bytes in 1,655 blocks are indirectly lost in loss record 348 of 349
Comment 4 Jaromír Končický 2013-11-12 10:04:15 EST
Created attachment 823016 [details]
diff between 1.0.40 and 1.0.41

I figured out that cups-browsed from version 1.0.40 does not leak but 1.0.41 does, so the bug was most probably introduced in 1.0.41. I will look deeper in the code and try to find the place where it leaks.
Comment 5 Tim Waugh 2013-11-12 10:16:36 EST
The valgrind trace can usually pinpoint that sort of thing fairly precisely.
Comment 6 Jaromír Končický 2013-11-12 11:30:48 EST
Created attachment 823044 [details]

Finally I managed to fix this problem, it was really very small negligence of freeing allocated memory and structures in newly added code, causing the infinite leaks.
Comment 7 Jiri Popelka 2013-11-12 11:45:30 EST
(In reply to jkoncick from comment #6)
> Created attachment 823044 [details]
> patch

> Finally I managed to fix this problem

/me would be cautious saying it after experience with bug #959682, comment #10 :-)

Let's see what our leaks discoverer thinks about it.
Zdenek, could you give it a try ?
Comment 8 Zdenek Kabelac 2013-11-12 13:41:03 EST
Created attachment 823093 [details]
New valgrind trace

It has got certainly much better since the growth speed has been significantly lowered. However in the attached valgrind log there are still couple 'definitely lost' elements present. 

I guess the most important one is this:
8,303 bytes in 437 blocks are definitely lost in loss record 278 of 283
   at 0x4C2945D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x762F1D9: strdup (strdup.c:42)
   by 0x10D787: generate_local_queue (cups-browsed.c:927)
   by 0x10E307: found_cups_printer (cups-browsed.c:1382)
   by 0x10EA95: browse_poll (cups-browsed.c:1915)
   by 0x6BF6F12: g_timeout_dispatch (gmain.c:4448)
   by 0x6BF6364: g_main_context_dispatch (gmain.c:3065)
   by 0x6BF66F7: g_main_context_iterate.isra.23 (gmain.c:3710)
   by 0x6BF6B09: g_main_loop_run (gmain.c:3904)
   by 0x10B7B8: main (cups-browsed.c:2612)

Then there are some CRYPTO related things - unsure about their impact.
Comment 9 Jaromír Končický 2013-11-14 04:26:59 EST
Created attachment 823828 [details]
new (hopefully final) patch

You're right, I overlooked that one leak.
Now I eliminated all "definitely lost" leaks, you can test it here:
If everything is ok, then I can add this patch into repository.
Comment 10 Fedora Update System 2013-11-14 06:43:21 EST
cups-filters-1.0.41-3.fc20 has been submitted as an update for Fedora 20.
Comment 11 Fedora Update System 2013-11-14 06:43:46 EST
cups-filters-1.0.41-3.fc19 has been submitted as an update for Fedora 19.
Comment 12 Zdenek Kabelac 2013-11-14 06:44:13 EST
Created attachment 823897 [details]
Valgring trace with fixed memleak

Here is my latest valgrind trace to confirm I'm not seeing any 'definitely lost' elements this time - though the shutdown logic in the code might be improved as well.

Compared with the 1st. trace I've added more debuginfo packages for full traces of cryptolibs.

Looks like certain buffers in-use are taken from stack and not fully aligned/cleared before its use ?

Number of 'Conditional jump or move depends on uninitialized value(s)' looks a bit scary - but it seem this is a bug in other package (cups/crypto?)
Comment 13 Fedora Update System 2013-11-14 14:14:50 EST
Package cups-filters-1.0.41-3.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing cups-filters-1.0.41-3.fc20'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).
Comment 14 Fedora Update System 2013-11-23 22:54:32 EST
cups-filters-1.0.41-4.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 15 Fedora Update System 2013-12-07 02:04:38 EST
cups-filters-1.0.41-4.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.