Skip to content

Commit

Permalink
Start patching up memory leaks from string_to_cstring behaviour change
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@2818 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
dsugalski committed Dec 15, 2002
1 parent 899e484 commit 6b00ffb
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build_nativecall.pl
Expand Up @@ -185,7 +185,7 @@ sub make_arg {
return "(double)NUM_REG($regnum)";
};
/t/ && do {my $regnum = $reg_ref->{s}++;
return "string_to_c_string(interpreter, STR_REG($regnum))";
return "string_to_cstring(interpreter, STR_REG($regnum))";
};

}
Expand Down
2 changes: 1 addition & 1 deletion build_tools/build_nativecall.pl
Expand Up @@ -185,7 +185,7 @@ sub make_arg {
return "(double)NUM_REG($regnum)";
};
/t/ && do {my $regnum = $reg_ref->{s}++;
return "string_to_c_string(interpreter, STR_REG($regnum))";
return "string_to_cstring(interpreter, STR_REG($regnum))";
};

}
Expand Down
3 changes: 3 additions & 0 deletions datatypes.c
Expand Up @@ -23,6 +23,9 @@ Parrot_get_datatype_enum(Interp *interpreter, STRING *typename)
if (!strcmp(datatype_names[i - enum_first_type], type))
return i;
}

free(type);

return enum_type_undef;
}

Expand Down
2 changes: 1 addition & 1 deletion include/parrot/string_funcs.h
Expand Up @@ -54,7 +54,7 @@ void string_init(void);
INTVAL string_index(const STRING *, UINTVAL idx);
INTVAL string_str_index(struct Parrot_Interp *interpreter, const STRING *s,
const STRING *s2, UINTVAL start);
const char *string_to_cstring(struct Parrot_Interp *, STRING *);
char *string_to_cstring(struct Parrot_Interp *, STRING *);

#endif

Expand Down
27 changes: 21 additions & 6 deletions spf_render.c
Expand Up @@ -182,7 +182,11 @@ gen_sprintf_call(struct Parrot_Interp *interpreter, char *out,
info->width = PARROT_SPRINTF_BUFFER_SIZE;
}
ts = uint_to_str(interpreter, tc, info->width, 10, 0);
strcpy(out + i, string_to_cstring(interpreter, ts));
{
char *tempstr = string_to_cstring(interpreter, ts);
strcpy(out + i, tempstr);
free(tempstr);
}
i = strlen(out);
}

Expand All @@ -193,7 +197,11 @@ gen_sprintf_call(struct Parrot_Interp *interpreter, char *out,

out[i++] = '.';
ts = uint_to_str(interpreter, tc, info->prec, 10, 0);
strcpy(out + i, string_to_cstring(interpreter, ts));
{
char *tempstr = string_to_cstring(interpreter, ts);
strcpy(out + i, tempstr);
free(tempstr);
}
i = strlen(out);
}

Expand Down Expand Up @@ -565,10 +573,17 @@ Parrot_sprintf_format(struct Parrot_Interp *interpreter, STRING *pat,
(interpreter, info.type, obj);
gen_sprintf_call(interpreter, tc, &info, ch);
ts = cstr2pstr(tc);
/* XXX lost precision if %Hg or whatever */
snprintf(tc, PARROT_SPRINTF_BUFFER_SIZE,
string_to_cstring(interpreter, ts),
(double)thefloat);
/* XXX lost precision if %Hg or whatever
*/
{
char *tempstr = string_to_cstring(interpreter,
ts);

snprintf(tc, PARROT_SPRINTF_BUFFER_SIZE,
tempstr,
(double)thefloat);
free(tempstr);
}

#if _WIN32
/* Microsoft uses a retarded, broken, nonstandard
Expand Down
3 changes: 3 additions & 0 deletions src/datatypes.c
Expand Up @@ -23,6 +23,9 @@ Parrot_get_datatype_enum(Interp *interpreter, STRING *typename)
if (!strcmp(datatype_names[i - enum_first_type], type))
return i;
}

free(type);

return enum_type_undef;
}

Expand Down
27 changes: 21 additions & 6 deletions src/spf_render.c
Expand Up @@ -182,7 +182,11 @@ gen_sprintf_call(struct Parrot_Interp *interpreter, char *out,
info->width = PARROT_SPRINTF_BUFFER_SIZE;
}
ts = uint_to_str(interpreter, tc, info->width, 10, 0);
strcpy(out + i, string_to_cstring(interpreter, ts));
{
char *tempstr = string_to_cstring(interpreter, ts);
strcpy(out + i, tempstr);
free(tempstr);
}
i = strlen(out);
}

Expand All @@ -193,7 +197,11 @@ gen_sprintf_call(struct Parrot_Interp *interpreter, char *out,

out[i++] = '.';
ts = uint_to_str(interpreter, tc, info->prec, 10, 0);
strcpy(out + i, string_to_cstring(interpreter, ts));
{
char *tempstr = string_to_cstring(interpreter, ts);
strcpy(out + i, tempstr);
free(tempstr);
}
i = strlen(out);
}

Expand Down Expand Up @@ -565,10 +573,17 @@ Parrot_sprintf_format(struct Parrot_Interp *interpreter, STRING *pat,
(interpreter, info.type, obj);
gen_sprintf_call(interpreter, tc, &info, ch);
ts = cstr2pstr(tc);
/* XXX lost precision if %Hg or whatever */
snprintf(tc, PARROT_SPRINTF_BUFFER_SIZE,
string_to_cstring(interpreter, ts),
(double)thefloat);
/* XXX lost precision if %Hg or whatever
*/
{
char *tempstr = string_to_cstring(interpreter,
ts);

snprintf(tc, PARROT_SPRINTF_BUFFER_SIZE,
tempstr,
(double)thefloat);
free(tempstr);
}

#if _WIN32
/* Microsoft uses a retarded, broken, nonstandard
Expand Down
2 changes: 1 addition & 1 deletion src/string.c
Expand Up @@ -1057,7 +1057,7 @@ string_from_num(struct Parrot_Interp * interpreter, FLOATVAL f)
return Parrot_sprintf_c(interpreter, "%vg", f);
}

const char *
char *
string_to_cstring(struct Parrot_Interp * interpreter, STRING * s)
{

Expand Down
2 changes: 1 addition & 1 deletion string.c
Expand Up @@ -1057,7 +1057,7 @@ string_from_num(struct Parrot_Interp * interpreter, FLOATVAL f)
return Parrot_sprintf_c(interpreter, "%vg", f);
}

const char *
char *
string_to_cstring(struct Parrot_Interp * interpreter, STRING * s)
{

Expand Down

0 comments on commit 6b00ffb

Please sign in to comment.