Bug 1007762 - Memory leak in nss_Init
Memory leak in nss_Init
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: nss (Show other bugs)
6.5
s390x Linux
unspecified Severity medium
: rc
: ---
Assigned To: Elio Maldonado Batiz
BaseOS QE Security Team
:
: 888720 (view as bug list)
Depends On:
Blocks: 1071861
  Show dependency treegraph
 
Reported: 2013-09-13 05:32 EDT by Hubert Kario
Modified: 2014-07-03 14:33 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1071861 (view as bug list)
Environment:
Last Closed: 2014-07-02 09:42:19 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Hubert Kario 2013-09-13 05:32:17 EDT
Description of problem:
When running reproducer for bug 769616, valgrind reports a memory leak.

Version-Release number of selected component (if applicable):
nss-3.15.1-3.el6.s390x

How reproducible:
Always

Steps to Reproduce:
  cat <<EOF > ckfw_leaks_memory.c
#include <assert.h>
#include <nss.h>
#include <secmod.h>
#include <stdlib.h>

int main() {
  if (0 != NSS_NoDB_Init(NULL))
    assert(0);

  for (int i = 0; i < 256; ++i) {
    SECMODModule* mod = SECMOD_LoadUserModule("library=libnsspem.so name=PEM", NULL, PR_FALSE);
    if(!mod || !mod->loaded)
      assert(0);

    SECMOD_UnloadUserModule(mod);
    SECMOD_DestroyModule(mod);
  }

  NSS_Shutdown();

  return EXIT_SUCCESS;
}
EOF
gcc ckfw_leaks_memory.c -o ckfw_leaks_memory -g -std=c99 -pedantic -W -Wall -I/usr/include/nss3 -I/usr/include/nspr4 -lnss3
LD_PRELOAD=libnsspem.so valgrind --leak-check=full --error-exitcode=7 ./ckfw_leaks_memory

Actual results:
==15960== Memcheck, a memory error detector
==15960== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==15960== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==15960== Command: ./ckfw_leaks_memory
==15960== 
==15960== 
==15960== HEAP SUMMARY:
==15960==     in use at exit: 10,585 bytes in 89 blocks
==15960==   total heap usage: 83,922 allocs, 83,833 frees, 35,332,256 bytes allocated
==15960== 
==15960== 272 bytes in 1 blocks are definitely lost in loss record 68 of 75
==15960==    at 0x402BA84: calloc (vg_replace_malloc.c:593)
==15960==    by 0x43ADCB3: _PR_InitThreads (ptthread.c:939)
==15960==    by 0x439D517: _PR_InitStuff (prinit.c:180)
==15960==    by 0x439D7AD: PR_CallOnce (prinit.c:219)
==15960==    by 0x408E9C9: nss_Init (nssinit.c:548)
==15960==    by 0x408F943: NSS_NoDB_Init (nssinit.c:874)
==15960==    by 0x800008DD: main (ckfw_leaks_memory.c:7)
==15960== 
==15960== LEAK SUMMARY:
==15960==    definitely lost: 272 bytes in 1 blocks
==15960==    indirectly lost: 0 bytes in 0 blocks
==15960==      possibly lost: 0 bytes in 0 blocks
==15960==    still reachable: 10,313 bytes in 88 blocks
==15960==         suppressed: 0 bytes in 0 blocks
==15960== Reachable blocks (those to which a pointer was found) are not shown.
==15960== To see them, rerun with: --leak-check=full --show-reachable=yes
==15960== 
==15960== For counts of detected and suppressed errors, rerun with: -v
==15960== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 264 from 8)

Expected results:
No memory leaks

Additional info:
This bug might have been introduced by errata 12964, but couldn't be detected because of bug 823005 and issues described in bug 700359. This is NOT a regresion from 6.4.z.
Comment 1 Hubert Kario 2013-09-13 05:34:25 EDT
As marked in Hardware section, the issue is s390x specific.
Comment 2 RHEL Product and Program Management 2013-10-13 22:12:19 EDT
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.
Comment 3 Hubert Kario 2013-10-18 07:24:00 EDT
*** Bug 888720 has been marked as a duplicate of this bug. ***
Comment 4 Hubert Kario 2013-12-06 08:41:03 EST
Still present in nss-3.15.3-2.el6_5.s390x
Comment 7 Bob Relyea 2014-06-25 14:34:00 EDT
This is actually a test case error. Your testcase needs to call PR_Cleanup() if you want to test for memory leaks. The leaks are nspr globals, which get allocated once the first NSPR use and stay in use until PR_Cleanup().

bob
Comment 8 Hubert Kario 2014-07-02 09:42:19 EDT
As said in Comment #7, issue in test case.

After changes:
==38193== LEAK SUMMARY:
==38193==    definitely lost: 0 bytes in 0 blocks
==38193==    indirectly lost: 0 bytes in 0 blocks
==38193==      possibly lost: 0 bytes in 0 blocks
==38193==    still reachable: 1,447 bytes in 10 blocks
==38193==         suppressed: 0 bytes in 0 blocks
Comment 9 Kamil Dudka 2014-07-02 12:28:37 EDT
I have pushed a fix upstream for the curl tool (does not affect libcurl):

https://github.com/bagder/curl/commit/24c3cdce
Comment 10 Hubert Kario 2014-07-03 04:51:11 EDT
(In reply to Kamil Dudka from comment #9)
> I have pushed a fix upstream for the curl tool (does not affect libcurl):
> 
> https://github.com/bagder/curl/commit/24c3cdce

I'm not sure if the first one is needed, but we settled in for two cleanup commands from nspr:

 PL_ArenaFinish();
 PR_Cleanup();
Comment 11 Kamil Dudka 2014-07-03 14:33:33 EDT
(In reply to Hubert Kario from comment #10)
> I'm not sure if the first one is needed, but we settled in for two cleanup
> commands from nspr:
> 
>  PL_ArenaFinish();
>  PR_Cleanup();

Thanks!  I have added the call to PL_ArenaFinish():

https://github.com/bagder/curl/commit/d343033f

It eliminates some of the "still reachable" memory reported by valgrind.

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