Return-Path: X-Original-To: apmail-httpd-cvs-archive@www.apache.org Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D85ED102C2 for ; Sat, 20 Apr 2013 11:20:45 +0000 (UTC) Received: (qmail 23499 invoked by uid 500); 20 Apr 2013 11:20:45 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 23285 invoked by uid 500); 20 Apr 2013 11:20:45 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 23265 invoked by uid 99); 20 Apr 2013 11:20:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Apr 2013 11:20:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Apr 2013 11:20:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0F9AB23889E7; Sat, 20 Apr 2013 11:20:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1470155 - in /httpd/httpd/trunk/modules/lua: lua_request.c lua_request.h Date: Sat, 20 Apr 2013 11:20:22 -0000 To: cvs@httpd.apache.org From: humbedooh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130420112023.0F9AB23889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: humbedooh Date: Sat Apr 20 11:20:22 2013 New Revision: 1470155 URL: http://svn.apache.org/r1470155 Log: use ap_varbuf instead of allocating new strings each time we override an old one. This uses leaks less memory, but it's still not perfect (but it's a start - maybe I need to use a mutex for this, to override the original object without running into race conditions) Modified: httpd/httpd/trunk/modules/lua/lua_request.c httpd/httpd/trunk/modules/lua/lua_request.h Modified: httpd/httpd/trunk/modules/lua/lua_request.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1470155&r1=1470154&r2=1470155&view=diff ============================================================================== --- httpd/httpd/trunk/modules/lua/lua_request.c (original) +++ httpd/httpd/trunk/modules/lua/lua_request.c Sat Apr 20 11:20:22 2013 @@ -26,6 +26,7 @@ #include "scoreboard.h" #include "lua_dbd.h" #include "util_md5.h" +#include "util_varbuf.h" APLOG_USE_MODULE(lua); #define POST_MAX_VARS 500 @@ -1661,7 +1662,7 @@ static int lua_ivm_get(lua_State *L) { if (object) { if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number); else if (object->type == LUA_TNUMBER) lua_pushnumber(L, object->number); - else if (object->type == LUA_TSTRING) lua_pushlstring(L, object->string, object->size); + else if (object->type == LUA_TSTRING) lua_pushlstring(L, object->vb.buf, object->size); return 1; } else { @@ -1674,22 +1675,27 @@ static int lua_ivm_set(lua_State *L) { const char *key, *raw_key; const char *value = NULL; lua_ivm_object *object = NULL; + lua_ivm_object *old_object = NULL; + request_rec *r = ap_lua_check_request_rec(L, 1); key = luaL_checkstring(L, 2); luaL_checkany(L, 3); raw_key = apr_pstrcat(r->pool, "lua_ivm_", key, NULL); - /* This will require MaxConnectionsPerChild to be > 0, since it's - * essentially leaking memory as values are being overridden */ + apr_pool_userdata_get((void **)&old_object, raw_key, r->server->process->pool); object = apr_pcalloc(r->server->process->pool, sizeof(lua_ivm_object)); object->type = lua_type(L, 3); if (object->type == LUA_TNUMBER) object->number = lua_tonumber(L, 3); else if (object->type == LUA_TBOOLEAN) object->number = lua_tonumber(L, 3); else if (object->type == LUA_TSTRING) { value = lua_tolstring(L, 3, &object->size); - object->string = apr_pstrmemdup(r->server->process->pool, value, object->size); + ap_varbuf_init(r->server->process->pool, &object->vb, object->size); + ap_varbuf_strmemcat(&object->vb, value, object->size); } apr_pool_userdata_set(object, raw_key, NULL, r->server->process->pool); + if (old_object && old_object->type == LUA_TSTRING) { + ap_varbuf_free(&old_object->vb); + } return 0; } Modified: httpd/httpd/trunk/modules/lua/lua_request.h URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.h?rev=1470155&r1=1470154&r2=1470155&view=diff ============================================================================== --- httpd/httpd/trunk/modules/lua/lua_request.h (original) +++ httpd/httpd/trunk/modules/lua/lua_request.h Sat Apr 20 11:20:22 2013 @@ -16,7 +16,7 @@ */ #include "mod_lua.h" - +#include "util_varbuf.h" #ifndef _LUA_REQUEST_H_ #define _LUA_REQUEST_H_ @@ -40,8 +40,8 @@ typedef struct typedef struct { int type; size_t size; - void* string; lua_Number number; + struct ap_varbuf vb; } lua_ivm_object; #endif /* !_LUA_REQUEST_H_ */