Skip to content

Commit

Permalink
warn on NULL pointer passed to free_jvmti_refs()
Browse files Browse the repository at this point in the history
add missing calls to free_jvmti_refs()
init pointers to NULL if assigned by jvmti (for safety)
  • Loading branch information
jbalint committed Jul 14, 2013
1 parent b9a20d4 commit b27f026
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion jni_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ jvmtiError free_jvmti_refs(jvmtiEnv *jvmti, ...)
va_list s;
unsigned char *p;
va_start(s, jvmti);
while((p = va_arg(s, unsigned char *)) != (unsigned char *)-1)
while((p = va_arg(s, unsigned char *)) != (void *)-1)
{
if(!p)
{
fprintf(stderr, "WARNING: null pointer passed to free_jvmti_refs()\n");
continue;
}
jerr = (*jvmti)->Deallocate(jvmti, p);
/* if(check_jvmti_error(Gagent.jvmti, Gagent.jerr) != JVMTI_ERROR_NONE) */
/* jerr = Gagent.jerr; */
Expand Down
6 changes: 3 additions & 3 deletions lua_java/lj_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int lj_find_class(lua_State *L)
static int lj_get_class_fields(lua_State *L)
{
jint field_count;
jfieldID *fields;
jfieldID *fields = NULL;
jclass class;
int i;

Expand All @@ -61,7 +61,7 @@ static int lj_get_class_fields(lua_State *L)
static int lj_get_class_methods(lua_State *L)
{
jint method_count;
jmethodID *methods;
jmethodID *methods = NULL;
jclass class;
int i;

Expand All @@ -87,7 +87,7 @@ static int lj_get_class_methods(lua_State *L)
static int lj_get_source_filename(lua_State *L)
{
jobject class;
char *sourcefile;
char *sourcefile = NULL;

class = *(jobject *)luaL_checkudata(L, 1, "jobject_mt");
lua_pop(L, 1);
Expand Down
6 changes: 4 additions & 2 deletions lua_java/lj_field.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static int lj_get_field_id(lua_State *L)
static int lj_get_field_name(lua_State *L)
{
lj_field_id *field_id;
char *field_name;
char *sig;
char *field_name = NULL;
char *sig = NULL;

field_id = (lj_field_id *)luaL_checkudata(L, 1, "jfield_id_mt");
lua_pop(L, 1);
Expand All @@ -70,6 +70,8 @@ static int lj_get_field_name(lua_State *L)
lua_pushstring(L, sig);
lua_setfield(L, -2, "sig");

free_jvmti_refs(current_jvmti(), field_name, sig, (void *)-1);

return 1;
}

Expand Down
14 changes: 9 additions & 5 deletions lua_java/lj_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int lj_get_method_id(lua_State *L)
static int lj_get_local_variable_table(lua_State *L)
{
jmethodID method_id;
jvmtiLocalVariableEntry *vars;
jvmtiLocalVariableEntry *vars = NULL;
jint count;
int i;

Expand Down Expand Up @@ -112,7 +112,7 @@ static int lj_get_line_number_table(lua_State *L)
{
jmethodID method_id;
jint line_count;
jvmtiLineNumberEntry *lines;
jvmtiLineNumberEntry *lines = NULL;
int i;

method_id = *(jmethodID *)luaL_checkudata(L, 1, "jmethod_id_mt");
Expand All @@ -134,6 +134,8 @@ static int lj_get_line_number_table(lua_State *L)
lua_rawseti(L, -2, i+1);
}
lj_check_jvmti_error(L);

free_jvmti_refs(current_jvmti(), lines, (void *)-1);
}

return 1;
Expand All @@ -142,8 +144,8 @@ static int lj_get_line_number_table(lua_State *L)
static int lj_get_method_name(lua_State *L)
{
jmethodID method_id;
char *method_name;
char *sig;
char *method_name = NULL;
char *sig = NULL;

method_id = *(jmethodID *)luaL_checkudata(L, 1, "jmethod_id_mt");
lua_pop(L, 1);
Expand All @@ -157,7 +159,9 @@ static int lj_get_method_name(lua_State *L)
lua_setfield(L, -2, "name");
lua_pushstring(L, sig);
lua_setfield(L, -2, "sig");


free_jvmti_refs(current_jvmti(), method_name, sig, (void *)-1);

return 1;
}

Expand Down

0 comments on commit b27f026

Please sign in to comment.