mem-include-scan: verify memory #includes

If we use memory functions (malloc, free, strdup etc) in C sources in
libcurl and we fail to include curl_memory.h or memdebug.h we either
fail to properly support user-provided memory callbacks or the memory
leak system of the test suite fails.

After Ajit's report of a failure in the first category in http_proxy.c,
I spotted a few in the second category as well. These problems are now
tested for by test 1132 which runs a perl program that scans for and
attempts to check that we use the correct include files if a memory
related function is used in the source code.

Reported by: Ajit Dhumale
Bug: http://curl.haxx.se/mail/lib-2012-11/0125.html
This commit is contained in:
Daniel Stenberg 2012-11-17 00:59:42 +01:00
parent db4215f14a
commit ee588fe088
13 changed files with 156 additions and 10 deletions

View file

@ -67,10 +67,10 @@
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
/*
* Forward declarations.
*/

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -70,10 +70,10 @@
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
/*
* Forward declarations.
*/

View file

@ -45,6 +45,7 @@
#include "curlx.h"
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"

View file

@ -30,6 +30,10 @@
#include "curl_multibyte.h"
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
#ifdef WANT_IDN_PROTOTYPES
WINBASEAPI int WINAPI IdnToAscii(DWORD, const WCHAR *, int, WCHAR *, int);
WINBASEAPI int WINAPI IdnToUnicode(DWORD, const WCHAR *, int, WCHAR *, int);

View file

@ -28,9 +28,13 @@
#include "curl_hmac.h"
#include "warnless.h"
#include "curl_memory.h"
#if defined(USE_GNUTLS_NETTLE)
#include <nettle/md5.h>
/* The last #include file should be: */
#include "memdebug.h"
typedef struct md5_ctx MD5_CTX;
@ -54,6 +58,8 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
#elif defined(USE_GNUTLS)
#include <gcrypt.h>
/* The last #include file should be: */
#include "memdebug.h"
typedef gcry_md_hd_t MD5_CTX;
@ -436,6 +442,9 @@ static void Decode (UINT4 *output,
#endif /* CRYPTO LIBS */
/* The last #include file should be: */
#include "memdebug.h"
const HMAC_params Curl_HMAC_MD5[] = {
{
(HMAC_hinit_func) MD5_Init, /* Hash initialization function. */

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -24,12 +24,16 @@
#ifdef CURL_DOES_CONVERSIONS
#include <curl/curl.h>
#include "non-ascii.h"
#include "formdata.h"
#include "sendf.h"
#include "urldata.h"
#include <curl/curl.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
#ifdef HAVE_ICONV
#include <iconv.h>

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -32,6 +32,9 @@
#include <nks/thread.h>
#include <nks/synch.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
typedef struct
{

View file

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -19,7 +19,9 @@
* KIND, either express or implied.
*
***************************************************************************/
/*
* This file is 'mem-include-scan' clean. See test 1132.
*/
#include "setup.h"
#include "strdup.h"

View file

@ -44,6 +44,9 @@
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
const char *
curl_easy_strerror(CURLcode error)