Commit 44bca1ea authored by rswindell's avatar rswindell
Browse files

Address Coverity-reported resource leaks (in error conditions/handlers and

unused functions).
parent bb4b6af1
......@@ -1222,8 +1222,10 @@ js_exec(JSContext *cx, uintN argc, jsval *arglist)
}
JSSTRING_TO_MSTRING(cx, cmd, cstr, NULL);
if(cstr==NULL)
if(cstr==NULL) {
FREE_AND_NULL(p_startup_dir);
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(sbbs->external(cstr,mode,p_startup_dir)));
free(cstr);
......@@ -1418,6 +1420,7 @@ js_replace_text(JSContext *cx, uintN argc, jsval *arglist)
sbbs->text[i]=p;
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
}
free(p);
return(JS_TRUE);
}
......@@ -2543,8 +2546,11 @@ js_email(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
if(js_subj!=NULL)
JSSTRING_TO_MSTRING(cx, js_subj, subj, NULL);
if(subj==NULL)
if(subj==NULL) {
if(top != def)
free(top);
return JS_FALSE;
}
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(sbbs->email(usernumber,top,subj,mode)));
......@@ -3081,13 +3087,19 @@ js_cmdstr(JSContext *cx, uintN argc, jsval *arglist)
js_str = JS_ValueToString(cx, argv[i]);
if(fpath==def) {
JSSTRING_TO_MSTRING(cx, js_str, fpath, NULL);
if(fpath==NULL)
if(fpath==NULL) {
if(fspec != def)
free(fspec);
return JS_FALSE;
}
}
else if(fspec==def) {
JSSTRING_TO_MSTRING(cx, js_str, fspec, NULL);
if(fspec==NULL)
if(fspec==NULL) {
if(fpath != def)
free(fpath);
return JS_FALSE;
}
}
}
}
......@@ -3168,6 +3180,8 @@ js_listfiles(JSContext *cx, uintN argc, jsval *arglist)
}
else if(JSVAL_IS_STRING(argv[i])) {
js_str = JS_ValueToString(cx, argv[i]);
if(fspec != def)
FREE_AND_NULL(fspec);
JSSTRING_TO_MSTRING(cx, js_str, afspec, NULL);
if(afspec==NULL)
return JS_FALSE;
......@@ -3219,6 +3233,8 @@ js_listfileinfo(JSContext *cx, uintN argc, jsval *arglist)
}
else if(JSVAL_IS_STRING(argv[i])) {
js_str = JS_ValueToString(cx, argv[i]);
if(fspec != def && fspec != NULL)
free(fspec);
JSSTRING_TO_MSTRING(cx, js_str, fspec, NULL);
if(fspec==NULL)
return JS_FALSE;
......@@ -3437,8 +3453,11 @@ js_scanposts(JSContext *cx, uintN argc, jsval *arglist)
for(uintN i=1;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!JS_ValueToInt32(cx,argv[i],&mode))
if(!JS_ValueToInt32(cx,argv[i],&mode)) {
if(find != def)
free(find);
return JS_FALSE;
}
}
else if(JSVAL_IS_STRING(argv[i]) && find==def) {
JSVALUE_TO_MSTRING(cx, argv[i], find, NULL);
......
......@@ -531,8 +531,10 @@ js_getstr(JSContext *cx, uintN argc, jsval *arglist)
if(js_str!=NULL) {
JSSTRING_TO_MSTRING(cx, js_str, p2, NULL);
if(p2==NULL)
if(p2==NULL) {
free(p);
return JS_FALSE;
}
sprintf(p,"%.*s",(int)maxlen,p2);
free(p2);
}
......@@ -1235,17 +1237,24 @@ js_uselect(JSContext *cx, uintN argc, jsval *arglist)
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!JS_ValueToInt32(cx,argv[i],&num))
if(!JS_ValueToInt32(cx,argv[i],&num)) {
FREE_AND_NULL(title);
FREE_AND_NULL(item);
return JS_FALSE;
}
continue;
}
if((js_str=JS_ValueToString(cx, argv[i]))==NULL)
if((js_str=JS_ValueToString(cx, argv[i]))==NULL) {
FREE_AND_NULL(title);
FREE_AND_NULL(item);
return(JS_FALSE);
}
if(title==NULL) {
JSSTRING_TO_MSTRING(cx, js_str, title, NULL) // Magicsemicolon
if(title==NULL)
if(title==NULL) {
FREE_AND_NULL(item);
return JS_FALSE;
}
}
else if(item==NULL) {
JSSTRING_TO_MSTRING(cx, js_str, item, NULL) // Magicsemicolon
......
......@@ -133,7 +133,7 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
BOOL shareable=FALSE;
int file;
int file = -1;
uintN i;
jsint bufsize=2*1024;
JSString* str;
......@@ -196,7 +196,8 @@ js_open(JSContext *cx, uintN argc, jsval *arglist)
#endif
setvbuf(p->fp,NULL,_IOFBF,bufsize);
}
}
} else if(file >= 0)
close(file);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -1005,10 +1006,17 @@ js_iniRemoveKey(JSContext *cx, uintN argc, jsval *arglist)
if(p->fp==NULL)
return(JS_TRUE);
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
if(argc && argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL) {
JSVALUE_TO_MSTRING(cx, argv[0], section, NULL);
HANDLE_PENDING(cx, section);
}
JSVALUE_TO_MSTRING(cx, argv[1], key, NULL);
HANDLE_PENDING(cx, key);
if(JS_IsExceptionPending(cx)) {
FREE_AND_NULL(key);
FREE_AND_NULL(section);
return JS_FALSE;
}
if(key==NULL) {
JS_ReportError(cx, "Invalid NULL key specified");
FREE_AND_NULL(section);
......@@ -1501,6 +1509,8 @@ js_iniSetAllObjects(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
if((list=iniReadFile(p->fp))==NULL) {
JS_RESUMEREQUEST(cx, rc);
if(name != name_def)
free(name);
return JS_TRUE;
}
JS_RESUMEREQUEST(cx, rc);
......
......@@ -171,6 +171,8 @@ JSBool DLLCALL js_file_area_resolve(JSContext* cx, JSObject* areaobj, jsid id)
if(!JS_SetElement(cx, alt_list, l, &val))
return JS_FALSE;
}
if(name)
return(JS_TRUE);
}
#ifdef BUILD_JSDOCS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment