Skip to content

Commit

Permalink
Fixes and leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zeehio committed May 24, 2014
1 parent f8277f9 commit ccd1fe9
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 44 deletions.
19 changes: 10 additions & 9 deletions include/EST_TMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class EST_TMatrix : public EST_TVector<T>
/**@name access
* Basic access methods for matrices.
*/
//@{
///@{

/// return number of rows
ssize_t num_rows() const {return this->p_num_rows;}
Expand Down Expand Up @@ -201,7 +201,7 @@ class EST_TMatrix : public EST_TVector<T>
/// non-const element access operator
T &operator () (ssize_t row, ssize_t col) { return a(row,col); }

//@}
///@}

bool have_rows_before(ssize_t n) const;
bool have_columns_before(ssize_t n) const;
Expand Down Expand Up @@ -230,7 +230,7 @@ class EST_TMatrix : public EST_TVector<T>
* memory with the original, so altering values them alters
* the original.
*/
//@{
///@{

/// Make the vector `rv` a window onto row `r`
void row(EST_TVector<T> &rv, ssize_t r, ssize_t start_c=0, int len=-1);
Expand All @@ -240,12 +240,12 @@ class EST_TMatrix : public EST_TVector<T>
void sub_matrix(EST_TMatrix<T> &sm,
ssize_t r=0, ptrdiff_t numr=EST_ALL,
ssize_t c=0, ptrdiff_t numc=EST_ALL);
//@}
///@}

/**@name Copy in and out
* Copy data between buffers and the matrix.
*/
//@{
///@{
/** Copy row `r` of matrix to `buf`. `buf`
should be pre-malloced to the correct size.
*/
Expand Down Expand Up @@ -296,11 +296,11 @@ class EST_TMatrix : public EST_TVector<T>
void set_memory(T *buffer, ptrdiff_t offset, ssize_t rows, ssize_t columns,
int free_when_destroyed=0);

//@}
///@}

/**@name Matrix file input / output
*/
//@{
///@{
/// load Matrix from file - Not currently implemented.
EST_read_status load(const class EST_String &filename);
/// save Matrix to file `filename`
Expand All @@ -311,11 +311,12 @@ class EST_TMatrix : public EST_TVector<T>
{ssize_t i, j;
for (i = 0; i < a.num_rows(); ++i) {
for (j = 0; j < a.num_columns(); ++j)
st << a.a_no_check(i, j) << " "; st << std::endl;
st << a.a_no_check(i, j) << " ";
st << std::endl;
}
return st;
}
//@}
///@}

};

Expand Down
8 changes: 6 additions & 2 deletions main/bcat_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,21 @@ int main(int argc, char *argv[])

FILE *dest;

if ((dest=fopen(out_file, "wb")) == NULL)
if ((dest=fopen(out_file, "wb")) == NULL) {
EST_sys_error("Can't create '%s'", (const char *)out_file);
return -1;
}

EST_Litem *item;

for(item=files.head(); item; item = item->next())
{
FILE *src;

if ((src=fopen(files(item), "rb"))==NULL)
if ((src=fopen(files(item), "rb"))==NULL) {
EST_sys_error("can't read '%s'", (const char *)files(item));
return -1;
}

unsigned int n;
char buf[BUFFER_SIZE];
Expand Down
4 changes: 2 additions & 2 deletions main/pda_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void set_parameters(EST_Features &a_list, EST_Option &al);
void option_override(EST_Features &op, EST_Option al,
const EST_String &option, const EST_String &arg);

static int save_pm(EST_String filename, EST_Track fz);
static int save_pm(EST_String filename, const EST_Track& fz);



Expand Down Expand Up @@ -175,7 +175,7 @@ void set_parameters(EST_Features &op, EST_Option &al)
*/


static int save_pm(EST_String filename, EST_Track fz)
static int save_pm(EST_String filename,const EST_Track& fz)
{
ostream *outf;
float position, period;
Expand Down
10 changes: 0 additions & 10 deletions main/wfst_train_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static int wfst_train_main(int argc, char **argv)
EST_Option al;
EST_StrList files;
EST_String wfstfile;
FILE *ofd;

parse_command_line
(argc, argv,
Expand All @@ -79,15 +78,6 @@ static int wfst_train_main(int argc, char **argv)
"-heap <int> {210000}\n"+
" Set size of Lisp heap, needed for large rulesets\n",
files, al);

if (al.present("-o"))
{
if ((ofd=fopen(al.val("-o"),"w")) == NULL)
EST_error("can't open output file for writing \"%s\"",
(const char *)al.val("-o"));
}
else
ofd = stdout;

if (al.present("-wfst"))
wfstfile = al.val("-wfst");
Expand Down
16 changes: 13 additions & 3 deletions rxp/stdio16.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,32 @@ CharacterEncoding GetFileEncoding(FILE16 *file)

int Fprintf(FILE16 *file, const char *format, ...)
{
int nchars;
va_list args;
va_start(args, format);
return Vfprintf(file, format, args);
nchars = Vfprintf(file, format, args);
va_end(args);
return nchars;
}

int Printf(const char *format, ...)
{
int nchars;
va_list args;
va_start(args, format);
return Vfprintf(Stdout, format, args);
nchars = Vfprintf(Stdout, format, args);
va_end(args);
return nchars;
}

int Sprintf(void *buf, CharacterEncoding enc, const char *format, ...)
{
int nchars;
va_list args;
va_start(args, format);
return Vsprintf(buf, enc, format, args);
nchars = Vsprintf(buf, enc, format, args);
va_end(args);
return nchars;
}

int Vprintf(const char *format, va_list args)
Expand Down Expand Up @@ -422,6 +431,7 @@ int Vfprintf(FILE16 *file, const char *format, va_list args)
int L;
#endif
int nchars = 0;
memset(buf, 0, BufferSize*sizeof(char8));

while((c = *format++))
{
Expand Down
6 changes: 4 additions & 2 deletions rxp/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ char *url_merge(const char *url, const char *base,
FILE16 *url_open(const char *url, const char *base, const char *type,
char **merged_url)
{
char *scheme, *host, *path, *m_url;
char *scheme =NULL, *host, *path, *m_url;
int port;
unsigned int i;
FILE16 *f;
Expand All @@ -377,8 +377,9 @@ FILE16 *url_open(const char *url, const char *base, const char *type,

/* Determine the merged URL */

if(!(m_url = url_merge(url, base, &scheme, &host, &port, &path)))
if(!(m_url = url_merge(url, base, &scheme, &host, &port, &path))) {
return 0;
}

#ifdef HAVE_LIBZ
len = strlen(m_url);
Expand Down Expand Up @@ -547,6 +548,7 @@ static FILE16 *http_open(const char *url,
{
LT_ERROR1(LEFILE, "Error: system call connect failed: %s\n",
Strerror());
close(s);
return 0;
}

Expand Down
55 changes: 42 additions & 13 deletions rxp/xmlparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ static int process_xml_decl(Parser p)
Char *Value, *cp;
char8 *value;
CharacterEncoding enc = CE_unknown;
Char c;
int c;

s->entity->ml_decl = ML_xml;

Expand Down Expand Up @@ -2913,15 +2913,20 @@ static int parse_entity_decl(Parser p, Entity ent, int line, int chpos)
require(skip_dtd_whitespace(p, p->external_pe_depth > 0));
require(parse_name(p, "for name in entity declaration"));
CopyName(name);

require(expect_dtd_whitespace(p, "after name in entity declaration"));
if (expect_dtd_whitespace(p, "after name in entity declaration") <0) {
Free(name);
return -1;
}

if(looking_at(p, "'") || looking_at(p, "\""))
{
Char *value;

unget(p->source);
require(parse_string(p, "for value in entity declaration", LT_entity));
if(parse_string(p, "for value in entity declaration", LT_entity) <0) {
Free(name);
return -1;
}
value = p->pbuf;
Consume(p->pbuf);

Expand All @@ -2933,16 +2938,26 @@ static int parse_entity_decl(Parser p, Entity ent, int line, int chpos)
char8 *publicid, *systemid;
NotationDefinition notation = 0;

require(parse_external_id(p, 1, &publicid, &systemid, 1, 1));
if (parse_external_id(p, 1, &publicid, &systemid, 1, 1) < 0) {
Free(name);
return -1;
}

require((t = skip_dtd_whitespace(p, p->external_pe_depth > 0)));
if ((t = skip_dtd_whitespace(p, p->external_pe_depth > 0)) < 0) {
Free(name);
return -1;
}
if(looking_at(p, "NDATA"))
{
if(t == 0)
return error(p, "Whitespace missing before NDATA");
if(pe)
return error(p, "NDATA not allowed for parameter entity");
require(expect_dtd_whitespace(p, "after NDATA"));
if (expect_dtd_whitespace(p, "after NDATA") <0) {
Free(name);
Free(systemid);
return -1;
}
require(parse_name(p, "for notation name in entity declaration"));
maybe_uppercase_name(p);
notation = FindNotationN(p->dtd, p->name, p->namelen);
Expand Down Expand Up @@ -2990,12 +3005,25 @@ static int parse_notation_decl(Parser p)
CopyName(name);
maybe_uppercase(p, name);

require(expect_dtd_whitespace(p, "after name in notation declaration"));
if (expect_dtd_whitespace(p, "after name in notation declaration") < 0) {
Free(name);
return -1;
}

require(parse_external_id(p, 1, &publicid, &systemid, 1, 0));

require(skip_dtd_whitespace(p, p->external_pe_depth > 0));
require(expect(p, '>', "at end of notation declaration"));
if (parse_external_id(p, 1, &publicid, &systemid, 1, 0) < 0) {
Free(name);
return -1;
}

if (skip_dtd_whitespace(p, p->external_pe_depth > 0) < 0) {
Free(name);
return -1;
}

if (expect(p, '>', "at end of notation declaration") < 0) {
Free(name);
return -1;
}

if((def = FindNotation(p->dtd, name)))
{
Expand Down Expand Up @@ -3139,7 +3167,7 @@ static int error(Parser p, const char8 *format, ...)
verror(&p->xbit, format, args);

p->state = PS_error;

va_end(args);
return -1;
}

Expand All @@ -3157,5 +3185,6 @@ static void warn(Parser p, const char8 *format, ...)
p->warning_callback(&bit, p->callback_arg);
else
ParserPerror(p, &bit);
va_end(args);
}

Loading

0 comments on commit ccd1fe9

Please sign in to comment.