httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject svn commit: r1470155 - in /httpd/httpd/trunk/modules/lua: lua_request.c lua_request.h
Date Sat, 20 Apr 2013 11:20:22 GMT
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_ */



Mime
View raw message