Skip to content

Fix memory leak in gnutls_certificate_set_ocsp_status_request_file()

The buffer holding the name of the previous file is leaked when gnutls_certificate_set_ocsp_status_request_file() is called more than once.

Code used for testing:

#include <gnutls/gnutls.h>

int main()
{
	gnutls_certificate_credentials_t x509_cred;

	gnutls_certificate_allocate_credentials(&x509_cred);
	gnutls_certificate_set_ocsp_status_request_file(x509_cred, "ocsp-status.der", 0);
	gnutls_certificate_set_ocsp_status_request_file(x509_cred, "ocsp-status.der", 0);

	gnutls_certificate_free_credentials(x509_cred);
	return 0;
}

Valgrind before patch:

$ valgrind --tool=memcheck --leak-check=yes ./ocspfileleaktest
Memcheck, a memory error detector
Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
Command: ./ocspfileleaktest

HEAP SUMMARY:
    in use at exit: 16 bytes in 1 blocks
  total heap usage: 1,319 allocs, 1,318 frees, 88,398 bytes allocated

   16 bytes in 1 blocks are definitely lost in loss record 1 of 1
   at 0x40291CC: malloc (vg_replace_malloc.c:296)
   by 0x4101870: _gnutls_strdup (mem.c:74)
   by 0x416637B: gnutls_certificate_set_ocsp_status_request_file (status_request.c:465)
   by 0x804866D: main (ocspfileleaktest.c:8)

LEAK SUMMARY:
   definitely lost: 16 bytes in 1 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 0 bytes in 0 blocks
   still reachable: 0 bytes in 0 blocks
        suppressed: 0 bytes in 0 blocks

For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Valgrind after patch:

$ valgrind --tool=memcheck --leak-check=yes ./ocspfileleaktest
Memcheck, a memory error detector
Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
Command: ./ocspfileleaktest


HEAP SUMMARY:
    in use at exit: 0 bytes in 0 blocks
  total heap usage: 1,319 allocs, 1,319 frees, 88,398 bytes allocated

All heap blocks were freed -- no leaks are possible

For counts of detected and suppressed errors, rerun with: -v

Merge request reports