diff options
| -rw-r--r-- | parse-events.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/parse-events.c b/parse-events.c index 8e79723..d831db7 100644 --- a/parse-events.c +++ b/parse-events.c | |||
| @@ -229,19 +229,14 @@ int pevent_pid_is_registered(struct pevent *pevent, int pid) | |||
| 229 | * we must add this pid. This is much slower than when cmdlines | 229 | * we must add this pid. This is much slower than when cmdlines |
| 230 | * are added before the array is initialized. | 230 | * are added before the array is initialized. |
| 231 | */ | 231 | */ |
| 232 | static int add_new_comm(struct pevent *pevent, char *comm, int pid) | 232 | static int add_new_comm(struct pevent *pevent, const char *comm, int pid) |
| 233 | { | 233 | { |
| 234 | struct cmdline *cmdlines = pevent->cmdlines; | 234 | struct cmdline *cmdlines = pevent->cmdlines; |
| 235 | const struct cmdline *cmdline; | 235 | const struct cmdline *cmdline; |
| 236 | struct cmdline key; | 236 | struct cmdline key; |
| 237 | 237 | ||
| 238 | if (!comm) | 238 | if (!pid) |
| 239 | die("malloc comm"); | ||
| 240 | |||
| 241 | if (!pid) { | ||
| 242 | free(comm); | ||
| 243 | return 0; | 239 | return 0; |
| 244 | } | ||
| 245 | 240 | ||
| 246 | /* avoid duplicates */ | 241 | /* avoid duplicates */ |
| 247 | key.pid = pid; | 242 | key.pid = pid; |
| @@ -250,7 +245,6 @@ static int add_new_comm(struct pevent *pevent, char *comm, int pid) | |||
| 250 | sizeof(*pevent->cmdlines), cmdline_cmp); | 245 | sizeof(*pevent->cmdlines), cmdline_cmp); |
| 251 | if (cmdline) { | 246 | if (cmdline) { |
| 252 | errno = EEXIST; | 247 | errno = EEXIST; |
| 253 | free(comm); | ||
| 254 | return -1; | 248 | return -1; |
| 255 | } | 249 | } |
| 256 | 250 | ||
| @@ -261,7 +255,10 @@ static int add_new_comm(struct pevent *pevent, char *comm, int pid) | |||
| 261 | } | 255 | } |
| 262 | 256 | ||
| 263 | cmdlines[pevent->cmdline_count].pid = pid; | 257 | cmdlines[pevent->cmdline_count].pid = pid; |
| 264 | cmdlines[pevent->cmdline_count].comm = comm; | 258 | cmdlines[pevent->cmdline_count].comm = strdup(comm); |
| 259 | if (!cmdlines[pevent->cmdline_count].comm) | ||
| 260 | die("malloc comm"); | ||
| 261 | |||
| 265 | if (cmdlines[pevent->cmdline_count].comm) | 262 | if (cmdlines[pevent->cmdline_count].comm) |
| 266 | pevent->cmdline_count++; | 263 | pevent->cmdline_count++; |
| 267 | 264 | ||
| @@ -285,7 +282,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid) | |||
| 285 | struct cmdline_list *item; | 282 | struct cmdline_list *item; |
| 286 | 283 | ||
| 287 | if (pevent->cmdlines) | 284 | if (pevent->cmdlines) |
| 288 | return add_new_comm(pevent, strdup(comm), pid); | 285 | return add_new_comm(pevent, comm, pid); |
| 289 | 286 | ||
| 290 | item = malloc_or_die(sizeof(*item)); | 287 | item = malloc_or_die(sizeof(*item)); |
| 291 | item->comm = strdup(comm); | 288 | item->comm = strdup(comm); |
