Skip to content

Commit

Permalink
Fix memory leak in break_string
Browse files Browse the repository at this point in the history
  • Loading branch information
cotillion committed Oct 5, 2024
1 parent 4c6d276 commit e5529da
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ extern int d_flag; /* for debugging purposes */
extern struct object *previous_ob;
struct object *vbfc_object;

#ifndef tolower /* On some systems this is a function */
extern int tolower (int);
#endif

/*****************************************************
This is the parser used by the efun parse_command
Expand Down Expand Up @@ -2008,22 +2004,23 @@ process_value(char *str, int other_ob)
* Returns: A string with newline separated strings
*/
char *
break_string(char *str, int width, struct svalue *indent)
break_string(char *str, int width, const struct svalue *indent)
{
char *fstr, *istr;
struct vector *lines;
long long l;
int il, nchar, space, indlen;

size_t len = strlen(str);
if (len == 0) {
return make_mstring("");
}

if (!indent)
istr = 0;

istr = NULL;
else if (indent->type == T_NUMBER && indent->u.number >= 0 && indent->u.number < 1000)
{
l = indent->u.number;
istr = xalloc((size_t)l + 1);
for (il = 0; il < l; il++)
istr = xalloc(indent->u.number + 1);
for (il = 0; il < indent->u.number; il++)
istr[il] = ' ';
istr[il] = 0;
}
Expand All @@ -2044,19 +2041,13 @@ break_string(char *str, int width, struct svalue *indent)
else
indlen = 0;

l = strlen(str);
if (l == 0) {
return make_mstring("");
}

/*
* Split with newlines
*/
space = -1;
nchar = 0;
l = strlen(str);
fstr = str;
for (il = 0; il < l; il++)
for (il = 0; il < len; il++)
{
if (fstr[il] == ' ')
space = il;
Expand Down

0 comments on commit e5529da

Please sign in to comment.