Skip to content

Commit

Permalink
Use lua_newuserdata() instead of strdup() so that lua can manage the …
Browse files Browse the repository at this point in the history
…memory.
  • Loading branch information
Brian Maher committed Jul 11, 2009
1 parent 4f7f2cf commit 93c0eb9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lua_zlib.c
@@ -1,9 +1,9 @@
#include <zlib.h>
#include <lua.h>
#include <ctype.h>
#include <lauxlib.h>
#include <lua.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <zlib.h>

static int lz_deflate(lua_State *L);
static int lz_deflate_delete(lua_State *L);
Expand All @@ -12,10 +12,12 @@ static int lz_inflate(lua_State *L);

//////////////////////////////////////////////////////////////////////
static int lz_version(lua_State *L) {
char* version = strdup(zlibVersion());
char* cur = version;
const char* version = zlibVersion();
int count = strlen(version) + 1;
char* cur = (char*)memcpy(lua_newuserdata(L, count),
version, count);

int count = 0;
count = 0;
while ( *cur ) {
char* begin = cur;
// Find all digits:
Expand All @@ -30,7 +32,6 @@ static int lz_version(lua_State *L) {
}
while ( *cur && ! isdigit(*cur) ) cur++;
}
free(version);

return count;
}
Expand Down

0 comments on commit 93c0eb9

Please sign in to comment.