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)
| r5620 | r5623 | |
|---|---|---|
| 930 | 930 | |
| 931 | 931 | static int core_dump(struct cw_dynstr **ds_p, int argc, char *argv[]) |
| 932 | 932 | { |
| 933 | struct cw_dynstr *buf = NULL; | |
| 933 | struct cw_dynstr *ds = NULL; | |
| 934 | 934 | int res; |
| 935 | 935 | |
| 936 | 936 | CW_UNUSED(ds_p); |
| --- | --- | |
| 943 | 943 | if (!strcmp(argv[3], "halt")) { |
| 944 | 944 | *(int *)0 = 1; |
| 945 | 945 | } 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" | |
| 947 | 947 | "generate-core-file\n" |
| 948 | 948 | "quit\n" |
| 949 | 949 | "EOF\n", |
| 950 | 950 | _argv[0], cw_mainpid); |
| 951 | 951 | |
| 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)) | |
| 956 | 962 | cw_log(CW_LOG_ERROR, "Out of memory!\n"); |
| 957 | 963 | } |
| 958 | 964 | |
| --- | --- | |
| 993 | 999 | if (!cmd->error) { |
| 994 | 1000 | if ((fd = popen(cmd->data, "r"))) { |
| 995 | 1001 | 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); | |
| 997 | 1003 | pclose(fd); |
| 998 | 1004 | } else |
| 999 | 1005 | cw_dynstr_printf(ds_p, "popen: %s\n", strerror(errno)); |
| --- | --- | |
| 1004 | 1010 | cw_dynstr_free(&cmd); |
| 1005 | 1011 | } |
| 1006 | 1012 | |
| 1007 | if (i != RESULT_SUCCESS) | |
| 1013 | if (unlikely(i != RESULT_SUCCESS)) | |
| 1008 | 1014 | cw_log(CW_LOG_ERROR, "Out of memory!\n"); |
| 1009 | 1015 | |
| 1010 | 1016 | return i; |
![Home changeset 5623 [home]](/images/logo.png?1180520111)
RSS Feeds