Skip to content

Commit

Permalink
fixing coverity found defects - resource leakage
Browse files Browse the repository at this point in the history
(cherry picked from commit e09f09a)
(cherry picked from commit 21083e8)
  • Loading branch information
ph4r05 authored and liviuchircu committed Jan 18, 2016
1 parent 1f7d58e commit 853702b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion daemonize.c
Expand Up @@ -213,7 +213,7 @@ void clean_write_pipeend(void)
*/
int daemonize(char* name, int * own_pgid)
{
FILE *pid_stream;
FILE *pid_stream = NULL;
pid_t pid;
int r, p,rc;
int pid_items;
Expand Down Expand Up @@ -336,6 +336,7 @@ int daemonize(char* name, int * own_pgid)
if (r<=0) {
LM_ERR("unable to write pgid to file %s: %s\n",
pid_file, strerror(errno));
fclose(pid_stream);
goto error;
}
fclose(pid_stream);
Expand Down
2 changes: 2 additions & 0 deletions modules/db_text/dbt_file.c
Expand Up @@ -497,6 +497,8 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
clean:
/// ????? FILL IT IN - incomplete row/column
// memory leak?!?! with last incomplete row
if(fin)
fclose(fin);
LM_DBG("error at row=%d col=%d c=%c\n", crow+1, ccol+1, c);
if(dtp)
dbt_table_free(dtp);
Expand Down
11 changes: 11 additions & 0 deletions modules/mi_fifo/fifo_fnc.c
Expand Up @@ -102,15 +102,23 @@ FILE* mi_create_fifo(void)
/* make sure the read fifo will not close */
mi_fifo_write=open(mi_fifo_name, O_WRONLY|O_NONBLOCK, 0);
if (mi_fifo_write<0) {
fclose(fifo_stream);
close(mi_fifo_read);
LM_ERR("fifo_write did not open: %s\n", strerror(errno));
return 0;
}
/* set read fifo blocking mode */
if ((opt=fcntl(mi_fifo_read, F_GETFL))==-1){
fclose(fifo_stream);
close(mi_fifo_read);
close(mi_fifo_write);
LM_ERR("fcntl(F_GETFL) failed: %s [%d]\n", strerror(errno), errno);
return 0;
}
if (fcntl(mi_fifo_read, F_SETFL, opt & (~O_NONBLOCK))==-1){
fclose(fifo_stream);
close(mi_fifo_read);
close(mi_fifo_write);
LM_ERR("cntl(F_SETFL) failed: %s [%d]\n", strerror(errno), errno);
return 0;
}
Expand All @@ -132,6 +140,9 @@ FILE* mi_init_fifo_server(char *fifo_name, int fifo_mode,
mi_buf = pkg_malloc(MAX_MI_FIFO_BUFFER);
reply_fifo_s = pkg_malloc(MAX_MI_FILENAME);
if ( mi_buf==NULL|| reply_fifo_s==NULL) {
fclose(fifo_stream);
close(mi_fifo_read);
close(mi_fifo_write);
LM_ERR("no more private memory\n");
return 0;
}
Expand Down

0 comments on commit 853702b

Please sign in to comment.