From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#8761: gnutls should use xmalloc not malloc Date: Mon, 30 May 2011 01:35:26 -0700 Organization: UCLA Computer Science Department Message-ID: <4DE356CE.6000305@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1306744570 32737 80.91.229.12 (30 May 2011 08:36:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 30 May 2011 08:36:10 +0000 (UTC) To: 8761@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 30 10:36:07 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QQxxG-0001tL-9w for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 May 2011 10:36:06 +0200 Original-Received: from localhost ([::1]:44995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxxF-0004pC-Ey for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 May 2011 04:36:05 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxxD-0004p7-QU for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:36:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQxxD-0005bZ-25 for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:36:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxxC-0005bU-T0 for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:36:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QQxxC-0001cE-9D; Mon, 30 May 2011 04:36:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 May 2011 08:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8761 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13067445406180 (code B ref -1); Mon, 30 May 2011 08:36:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 May 2011 08:35:40 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQxwq-0001bc-9F for submit@debbugs.gnu.org; Mon, 30 May 2011 04:35:40 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QQxwo-0001bP-5C for submit@debbugs.gnu.org; Mon, 30 May 2011 04:35:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQxwi-0005Yw-Au for submit@debbugs.gnu.org; Mon, 30 May 2011 04:35:33 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:53181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxwi-0005Ys-9K for submit@debbugs.gnu.org; Mon, 30 May 2011 04:35:32 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxwh-0004oo-6U for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:35:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQxwg-0005YV-7c for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:35:31 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:45741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQxwf-0005YP-Tb for bug-gnu-emacs@gnu.org; Mon, 30 May 2011 04:35:30 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id A064CA60001 for ; Mon, 30 May 2011 01:35:27 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oe7oEMxO-5HP for ; Mon, 30 May 2011 01:35:27 -0700 (PDT) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id F2B8539E80E0 for ; Mon, 30 May 2011 01:35:26 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 30 May 2011 04:36:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46797 Archived-At: Here's a proposed patch for the problem. * gnutls.c: Use Emacs's memory allocators. Without this change, the gnutls library would invoke malloc etc. directly, which causes problems on non-SYNC_INPUT hosts, and which runs afoul of improving memory_full behavior. (fn_gnutls_global_set_mem_functions): New macro or function pointer. (emacs_gnutls_global_init): Use it to specify xmalloc, xrealloc, xfree instead of the default malloc, realloc, free. (Fgnutls_boot): No need to check for memory allocation failure, since xmalloc does that for us. === modified file 'src/gnutls.c' --- src/gnutls.c 2011-05-23 00:03:40 +0000 +++ src/gnutls.c 2011-05-30 07:53:40 +0000 @@ -110,6 +110,10 @@ DEF_GNUTLS_FN (int, gnutls_global_init, (void)); DEF_GNUTLS_FN (void, gnutls_global_set_log_function, (gnutls_log_func)); DEF_GNUTLS_FN (void, gnutls_global_set_log_level, (int)); +DEF_GNUTLS_FN (void, gnutls_global_set_mem_functions, + (gnutls_alloc_function, gnutls_alloc_function, + gnutls_is_secure_function, gnutls_realloc_function, + gnutls_free_function)); DEF_GNUTLS_FN (int, gnutls_handshake, (gnutls_session_t)); DEF_GNUTLS_FN (int, gnutls_init, (gnutls_session_t *, gnutls_connection_end_t)); DEF_GNUTLS_FN (int, gnutls_priority_set_direct, @@ -168,6 +172,7 @@ LOAD_GNUTLS_FN (library, gnutls_global_init); LOAD_GNUTLS_FN (library, gnutls_global_set_log_function); LOAD_GNUTLS_FN (library, gnutls_global_set_log_level); + LOAD_GNUTLS_FN (library, gnutls_global_set_mem_functions); LOAD_GNUTLS_FN (library, gnutls_handshake); LOAD_GNUTLS_FN (library, gnutls_init); LOAD_GNUTLS_FN (library, gnutls_priority_set_direct); @@ -213,6 +218,7 @@ #define fn_gnutls_global_init gnutls_global_init #define fn_gnutls_global_set_log_function gnutls_global_set_log_function #define fn_gnutls_global_set_log_level gnutls_global_set_log_level +#define fn_gnutls_global_set_mem_functions gnutls_global_set_mem_functions #define fn_gnutls_handshake gnutls_handshake #define fn_gnutls_init gnutls_init #define fn_gnutls_priority_set_direct gnutls_priority_set_direct @@ -582,7 +588,11 @@ int ret = GNUTLS_E_SUCCESS; if (!gnutls_global_initialized) - ret = fn_gnutls_global_init (); + { + fn_gnutls_global_set_mem_functions (xmalloc, xmalloc, NULL, + xrealloc, xfree); + ret = fn_gnutls_global_init (); + } gnutls_global_initialized = 1; return gnutls_make_error (ret); @@ -768,8 +778,7 @@ { GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); x509_cred = XPROCESS (proc)->gnutls_x509_cred; - if (fn_gnutls_certificate_allocate_credentials (&x509_cred) < 0) - memory_full (); + fn_gnutls_certificate_allocate_credentials (&x509_cred); if (NUMBERP (verify_flags)) { @@ -792,8 +801,7 @@ { GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); anon_cred = XPROCESS (proc)->gnutls_anon_cred; - if (fn_gnutls_anon_allocate_client_credentials (&anon_cred) < 0) - memory_full (); + fn_gnutls_anon_allocate_client_credentials (&anon_cred); } else {