Changeset 5623

Fix memory and pipe leaks in core dump command handling

Committed by:  mjagdis
Date:  Feb 10 2010 * 19:07 (6 months ago)

Affected files:

callweaver/trunk/corelib/callweaver.c (unified diff)

r5620r5623
930930
931931 static int core_dump(struct cw_dynstr **ds_p, int argc, char *argv[])
932932 {
933 struct cw_dynstr *buf = NULL;
933 struct cw_dynstr *ds = NULL;
934934 int res;
935935
936936 CW_UNUSED(ds_p);
------
943943 if (!strcmp(argv[3], "halt")) {
944944 *(int *)0 = 1;
945945 } else {
946 cw_dynstr_printf(&buf, "gdb $( type -p \"%s\" ) %u <<EOF\n"
946 cw_dynstr_printf(&ds, "gdb $( type -p \"%s\" ) %u <<EOF\n"
947947 "generate-core-file\n"
948948 "quit\n"
949949 "EOF\n",
950950 _argv[0], cw_mainpid);
951951
952 if (buf && !buf->error) {
953 cw_safe_system(buf->data);
954 res = RESULT_SUCCESS;
955 } else
952 if (ds) {
953 if (!ds->error) {
954 cw_safe_system(ds->data);
955 res = RESULT_SUCCESS;
956 }
957
958 cw_dynstr_free(&ds);
959 }
960
961 if (unlikely(res != RESULT_SUCCESS))
956962 cw_log(CW_LOG_ERROR, "Out of memory!\n");
957963 }
958964
------
993999 if (!cmd->error) {
9941000 if ((fd = popen(cmd->data, "r"))) {
9951001 while ((i = fread(buf, 1, sizeof(buf), fd)) > 0)
996 if (cw_dynstr_printf(ds_p, "%.*s", i, buf))
1002 cw_dynstr_printf(ds_p, "%.*s", i, buf);
9971003 pclose(fd);
9981004 } else
9991005 cw_dynstr_printf(ds_p, "popen: %s\n", strerror(errno));
------
10041010 cw_dynstr_free(&cmd);
10051011 }
10061012
1007 if (i != RESULT_SUCCESS)
1013 if (unlikely(i != RESULT_SUCCESS))
10081014 cw_log(CW_LOG_ERROR, "Out of memory!\n");
10091015
10101016 return i;