dtpad: resove coverity issues

This commit is contained in:
Peter Howkins
2018-04-11 18:05:06 +01:00
parent 56b53a30a1
commit db88cb0d13
5 changed files with 14 additions and 15 deletions

View File

@@ -804,7 +804,10 @@ _poGetFileContents(char **contents, char *file)
if( (fp = fopen(file, "r")) == NULL )
return DtEDITOR_UNREADABLE_FILE;
stat(file, &statbuf);
if(stat(file, &statbuf) == -1) {
fclose(fp);
return DtEDITOR_UNREADABLE_FILE;
}
nbytes = statbuf.st_size;
/*
@@ -814,8 +817,10 @@ _poGetFileContents(char **contents, char *file)
* copy of the data before actually putting it into the widget.
*/
buf = (char *) malloc(nbytes + 1);
if (buf == NULL)
if (buf == NULL) {
fclose(fp);
return DtEDITOR_INSUFFICIENT_MEMORY;
}
nbytes = fread(buf, sizeof(char), nbytes, fp);
buf[nbytes] = '\0';