Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / wiretap / pppdump.c
1 /* pppdump.c
2  *
3  * $Id: pppdump.c,v 1.24 2002/08/28 20:30:45 jmayer Exp $
4  *
5  * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include "wtap-int.h"
26 #include "buffer.h"
27 #include "pppdump.h"
28 #include "file_wrappers.h"
29
30 #include <glib.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <string.h>
35
36 /*
37 pppdump records
38 Daniel Thompson (STMicroelectronics) <daniel.thompson@st.com>
39
40 +------+
41 | 0x07 |                              Reset time
42 +------+------+------+------+
43 |  t3  |  t2  |  t1  |  t0  |         t = time_t
44 +------+------+------+------+
45
46 +------+
47 | 0x06 |                              Time step (short)
48 +------+
49 |  ts  |                              ts = time step (tenths of seconds)
50 +------+
51
52 +------+
53 | 0x05 |                              Time step (long)
54 +------+------+------+------+
55 | ts3  | ts2  | ts1  | ts0  |         ts = time step (tenths of seconds)
56 +------+------+------+------+
57
58 +------+
59 | 0x04 |                              Receive deliminator (not seen in practice)
60 +------+
61
62 +------+
63 | 0x03 |                              Send deliminator (not seen in practice)
64 +------+
65
66 +------+
67 | 0x02 |                              Received data
68 +------+------+
69 |  n1  |  n0  |                       n = number of bytes following
70 +------+------+
71 |    data     |
72 |             |
73
74 +------+
75 | 0x01 |                              Sent data
76 +------+------+
77 |  n1  |  n0  |                       n = number of bytes following
78 +------+------+
79 |    data     |
80 |             |
81 */
82
83 #define PPPD_SENT_DATA          0x01
84 #define PPPD_RECV_DATA          0x02
85 #define PPPD_SEND_DELIM         0x03
86 #define PPPD_RECV_DELIM         0x04
87 #define PPPD_TIME_STEP_LONG     0x05
88 #define PPPD_TIME_STEP_SHORT    0x06
89 #define PPPD_RESET_TIME         0x07
90
91 /* this buffer must be at least (2*PPPD_MTU) + sizeof(ppp_header) + sizeof(lcp_header) +
92  * sizeof(ipcp_header). PPPD_MTU is *very* rarely larger than 1500 so this value is fine
93  */
94 #define PPPD_BUF_SIZE           8192
95
96 typedef enum {
97         DIRECTION_SENT,
98         DIRECTION_RECV
99 } direction_enum;
100
101 static gboolean pppdump_read(wtap *wth, int *err, long *data_offset);
102 static gboolean pppdump_seek_read(wtap *wth, long seek_off,
103         union wtap_pseudo_header *pseudo_header, guint8 *pd, int len, int *err);
104
105 /*
106  * Information saved about a packet, during the initial sequential pass
107  * through the file, to allow us to later re-read it when randomly
108  * reading packets.
109  *
110  * "offset" is the offset in the file of the first data chunk containing data
111  * from that packet; note that it may also contain data from previous
112  * packets.
113  *
114  * "num_bytes_to_skip" is the number of bytes from previous packets in that
115  * first data chunk.
116  *
117  * "dir" is the direction of the packet.
118  */
119 typedef struct {
120         long            offset;
121         int             num_bytes_to_skip;
122         direction_enum  dir;
123 } pkt_id;
124
125 /*
126  * Information about a packet currently being processed.  There is one of
127  * these for the sent packet being processed and one of these for the
128  * received packet being processed, as we could be in the middle of
129  * processing both a received packet and a sent packet.
130  *
131  * "dir" is the direction of the packet.
132  *
133  * "cnt" is the number of bytes of packet data we've accumulated.
134  *
135  * "esc" is TRUE if the next byte we see is escaped (and thus must be XORed
136  * with 0x20 before saving it), FALSE otherwise.
137  *
138  * "buf" is a buffer containing the packet data we've accumulated.
139  *
140  * "id_offset" is the offset in the file of the first data chunk
141  * containing data from the packet we're processing.
142  *
143  * "sd_offset" is the offset in the file of the first data byte from
144  * the packet we're processing - which isn't necessarily right after
145  * the header of the first data chunk, as we may already have assembled
146  * packets from that chunk.
147  *
148  * "cd_offset" is the offset in the file of the current data chunk we're
149  * processing.
150  */
151 typedef struct {
152         direction_enum  dir;
153         int             cnt;
154         gboolean        esc;
155         guint8          buf[PPPD_BUF_SIZE];
156         long            id_offset;
157         long            sd_offset;
158         long            cd_offset;
159 } pkt_t;
160
161 /*
162  * This keeps state used while processing records.
163  *
164  * "timestamp" is the seconds portion of the current time stamp value,
165  * as updated from PPPD_RESET_TIME, PPPD_TIME_STEP_LONG, and
166  * PPPD_TIME_STEP_SHORT records.  "tenths" is the tenths-of-seconds
167  * portion.
168  *
169  * "spkt" and "rpkt" are "pkt_t" structures for the sent and received
170  * packets we're currently working on.
171  *
172  * "offset" is the current offset in the file.
173  *
174  * "num_bytes" and "pkt" are information saved when we finish accumulating
175  * the data for a packet, if the data chunk we're working on still has more
176  * data in it:
177  *
178  *      "num_bytes" is the number of bytes of additional data remaining
179  *      in the chunk after we've finished accumulating the data for the
180  *      packet.
181  *
182  *      "pkt" is the "pkt_t" for the type of packet the data chunk is for
183  *      (sent or received packet).
184  *
185  * "seek_state" is another state structure used while processing records
186  * when doing a seek-and-read.  (That structure doesn't itself have a
187  * "seek_state" structure.)
188  *
189  * "pids" is a GPtrArray of pointers to "pkt_id" structures for all the
190  * packets we've seen during the initial sequential pass, to allow us to
191  * later retrieve them with random accesses.
192  *
193  * "pkt_cnt" is the number of packets we've seen up to this point in the
194  * sequential pass.
195  */
196 typedef struct _pppdump_t {
197         time_t                  timestamp;
198         guint                   tenths;
199         pkt_t                   spkt;
200         pkt_t                   rpkt;
201         long                    offset;
202         int                     num_bytes;
203         pkt_t                   *pkt;
204         struct _pppdump_t       *seek_state;
205         GPtrArray               *pids;
206         guint                   pkt_cnt;
207 } pppdump_t;
208
209 static int
210 process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
211     int *err, pkt_id *pid);
212
213 static gboolean
214 collate(pppdump_t*, FILE_T fh, int *err, guint8 *pd, int *num_bytes,
215                 direction_enum *direction, pkt_id *pid, int num_bytes_to_skip);
216
217 static void
218 pppdump_close(wtap *wth);
219
220 static void
221 init_state(pppdump_t *state)
222 {
223
224         state->num_bytes = 0;
225         state->pkt = NULL;
226
227         state->spkt.dir = DIRECTION_SENT;
228         state->spkt.cnt = 0;
229         state->spkt.esc = FALSE;
230         state->spkt.id_offset = 0;
231         state->spkt.sd_offset = 0;
232         state->spkt.cd_offset = 0;
233
234         state->rpkt.dir = DIRECTION_RECV;
235         state->rpkt.cnt = 0;
236         state->rpkt.esc = FALSE;
237         state->rpkt.id_offset = 0;
238         state->rpkt.sd_offset = 0;
239         state->rpkt.cd_offset = 0;
240
241         state->seek_state = NULL;
242         state->offset = 0x100000; /* to detect errors during development */
243 }
244
245
246 int
247 pppdump_open(wtap *wth, int *err)
248 {
249         guint8          buffer[6];      /* Looking for: 0x07 t3 t2 t1 t0 ID */
250         pppdump_t       *state;
251
252         /* There is no file header, only packet records. Fortunately for us,
253         * timestamp records are separated from packet records, so we should
254         * find an "initial time stamp" (i.e., a "reset time" record, or
255         * record type 0x07) at the beginning of the file. We'll check for
256         * that, plus a valid record following the 0x07 and the four bytes
257         * representing the timestamp.
258         */
259
260         wtap_file_read_unknown_bytes(buffer, sizeof(buffer), wth->fh, err);
261
262         if (buffer[0] == PPPD_RESET_TIME &&
263                         (buffer[5] == PPPD_SENT_DATA ||
264                          buffer[5] == PPPD_RECV_DATA ||
265                          buffer[5] == PPPD_TIME_STEP_LONG ||
266                          buffer[5] == PPPD_TIME_STEP_SHORT ||
267                          buffer[5] == PPPD_RESET_TIME)) {
268
269                 goto my_file_type;
270         }
271         else {
272                 return 0;
273         }
274
275   my_file_type:
276
277         if (file_seek(wth->fh, 5, SEEK_SET, err) == -1)
278                 return -1;
279
280         state = wth->capture.generic = g_malloc(sizeof(pppdump_t));
281         state->timestamp = pntohl(&buffer[1]);
282         state->tenths = 0;
283
284         init_state(state);
285
286         state->offset = 5;
287         wth->file_encap = WTAP_ENCAP_PPP_WITH_PHDR;
288         wth->file_type = WTAP_FILE_PPPDUMP;
289
290         wth->snapshot_length = PPPD_BUF_SIZE; /* just guessing */
291         wth->subtype_read = pppdump_read;
292         wth->subtype_seek_read = pppdump_seek_read;
293         wth->subtype_close = pppdump_close;
294
295         state->seek_state = g_malloc(sizeof(pppdump_t));
296
297         /* If we have a random stream open, we're going to be reading
298            the file randomly; set up a GPtrArray of pointers to
299            information about how to retrieve the data for each packet. */
300         if (wth->random_fh != NULL)
301                 state->pids = g_ptr_array_new();
302         else
303                 state->pids = NULL;
304         state->pkt_cnt = 0;
305
306         return 1;
307 }
308
309 /* Find the next packet and parse it; called from wtap_loop(). */
310 static gboolean
311 pppdump_read(wtap *wth, int *err, long *data_offset)
312 {
313         int             num_bytes;
314         direction_enum  direction;
315         guint8          *buf;
316         pppdump_t       *state;
317         pkt_id          *pid;
318
319         buffer_assure_space(wth->frame_buffer, PPPD_BUF_SIZE);
320         buf = buffer_start_ptr(wth->frame_buffer);
321
322         state = wth->capture.generic;
323
324         /* If we have a random stream open, allocate a structure to hold
325            the information needed to read this packet's data again. */
326         if (wth->random_fh != NULL) {
327                 pid = g_new(pkt_id, 1);
328                 if (!pid) {
329                         *err = errno;   /* assume a malloc failed and set "errno" */
330                         return FALSE;
331                 }
332                 pid->offset = 0;
333         } else
334                 pid = NULL;     /* sequential only */
335
336         if (!collate(state, wth->fh, err, buf, &num_bytes, &direction,
337             pid, 0)) {
338                 if (pid != NULL)
339                         g_free(pid);
340                 return FALSE;
341         }
342
343         if (pid != NULL)
344                 pid->dir = direction;
345
346         if (pid != NULL)
347                 g_ptr_array_add(state->pids, pid);
348         /* The user's data_offset is not really an offset, but a packet number. */
349         *data_offset = state->pkt_cnt;
350         state->pkt_cnt++;
351
352         wth->phdr.len           = num_bytes;
353         wth->phdr.caplen        = num_bytes;
354         wth->phdr.ts.tv_sec     = state->timestamp;
355         wth->phdr.ts.tv_usec    = state->tenths * 100000;
356         wth->phdr.pkt_encap     = WTAP_ENCAP_PPP_WITH_PHDR;
357
358         wth->pseudo_header.p2p.sent = (direction == DIRECTION_SENT ? TRUE : FALSE);
359
360         return TRUE;
361 }
362
363 /* Returns number of bytes copied for record, -1 if failure.
364  *
365  * This is modeled after pppdump.c, the utility to parse pppd log files; it comes with the ppp
366  * distribution.
367  */
368 static int
369 process_data(pppdump_t *state, FILE_T fh, pkt_t *pkt, int n, guint8 *pd,
370     int *err, pkt_id *pid)
371 {
372         int     c;
373         int     num_bytes = n;
374         int     num_written;
375
376         for (; num_bytes > 0; --num_bytes) {
377                 c = file_getc(fh);
378                 state->offset++;
379                 switch (c) {
380                         case EOF:
381                                 if (*err == 0) {
382                                         *err = WTAP_ERR_SHORT_READ;
383                                 }
384                                 return -1;
385                                 break;
386
387                         case 0x7e:
388                                 /*
389                                  * Flag Sequence for RFC 1662 HDLC-like
390                                  * framing.
391                                  *
392                                  * As this is a raw trace of octets going
393                                  * over the wire, and that might include
394                                  * the login sequence, there is no
395                                  * guarantee that *only* PPP traffic
396                                  * appears in this file, so there is no
397                                  * guarantee that the first 0x7e we see is
398                                  * a start flag sequence, and therefore we
399                                  * cannot safely ignore all characters up
400                                  * to the first 0x7e, and therefore we
401                                  * might end up with some bogus PPP
402                                  * packets.
403                                  */
404                                 if (pkt->cnt > 0) {
405                                         /*
406                                          * We've seen stuff before this,
407                                          * so this is the end of a frame.
408                                          * Make a frame out of that stuff.
409                                          */
410                                         pkt->esc = FALSE;
411
412                                         num_written = pkt->cnt;
413                                         pkt->cnt = 0;
414                                         if (num_written <= 0) {
415                                                 return 0;
416                                         }
417
418                                         if (num_written > PPPD_BUF_SIZE) {
419                                                 *err = WTAP_ERR_UNC_OVERFLOW;
420                                                 return -1;
421                                         }
422
423                                         memcpy(pd, pkt->buf, num_written);
424
425                                         /*
426                                          * Remember the offset of the
427                                          * first record containing data
428                                          * for this packet, and how far
429                                          * into that record to skip to
430                                          * get to the beginning of the
431                                          * data for this packet; the number
432                                          * of bytes to skip into that record
433                                          * is the file offset of the first
434                                          * byte of this packet minus the
435                                          * file offset of the first byte of
436                                          * this record, minus 3 bytes for the
437                                          * header of this record (which, if
438                                          * we re-read this record, we will
439                                          * process, not skip).
440                                          */
441                                         if (pid) {
442                                                 pid->offset = pkt->id_offset;
443                                                 pid->num_bytes_to_skip =
444                                                     pkt->sd_offset - pkt->id_offset - 3;
445                                                 g_assert(pid->num_bytes_to_skip >= 0);
446                                         }
447
448                                         num_bytes--;
449                                         if (num_bytes > 0) {
450                                                 /*
451                                                  * There's more data in this
452                                                  * record.
453                                                  * Set the initial data offset
454                                                  * for the next packet.
455                                                  */
456                                                 pkt->id_offset = pkt->cd_offset;
457                                                 pkt->sd_offset = state->offset;
458                                         } else {
459                                                 /*
460                                                  * There is no more data in
461                                                  * this record.
462                                                  * Thus, we don't have the
463                                                  * initial data offset for
464                                                  * the next packet.
465                                                  */
466                                                 pkt->id_offset = 0;
467                                                 pkt->sd_offset = 0;
468                                         }
469                                         state->num_bytes = num_bytes;
470                                         state->pkt = pkt;
471                                         return num_written;
472                                 }
473                                 break;
474
475                         case 0x7d:
476                                 /*
477                                  * Control Escape octet for octet-stuffed
478                                  * RFC 1662 HDLC-like framing.
479                                  */
480                                 if (!pkt->esc) {
481                                         /*
482                                          * Control Escape not preceded by
483                                          * Control Escape; discard it
484                                          * but XOR the next octet with
485                                          * 0x20.
486                                          */
487                                         pkt->esc = TRUE;
488                                         break;
489                                 }
490                                 /*
491                                  * Control Escape preceded by Control Escape;
492                                  * treat it as an ordinary character,
493                                  * by falling through.
494                                  */
495
496                         default:
497                                 if (pkt->esc) {
498                                         /*
499                                          * This character was preceded by
500                                          * Control Escape, so XOR it with
501                                          * 0x20, as per RFC 1662's octet-
502                                          * stuffed framing, and clear
503                                          * the flag saying that the
504                                          * character should be escaped.
505                                          */
506                                         c ^= 0x20;
507                                         pkt->esc = FALSE;
508                                 }
509
510                                 pkt->buf[pkt->cnt++] = c;
511                                 if (pkt->cnt > PPPD_BUF_SIZE) {
512                                         *err = WTAP_ERR_UNC_OVERFLOW;
513                                         return -1;
514                                 }
515                                 break;
516                 }
517         }
518
519         /* we could have run out of bytes to read */
520         return 0;
521 }
522
523 /* Returns TRUE if packet data copied, FALSE if error occurred or EOF (no more records). */
524 static gboolean
525 collate(pppdump_t* state, FILE_T fh, int *err, guint8 *pd, int *num_bytes,
526                 direction_enum *direction, pkt_id *pid, int num_bytes_to_skip)
527 {
528         int             id;
529         pkt_t           *pkt = NULL;
530         int             n, num_written = 0;
531         guint32         time_long;
532         guint8          time_short;
533
534         /*
535          * Process any data left over in the current record when doing
536          * sequential processing.
537          */
538         if (state->num_bytes > 0) {
539                 g_assert(num_bytes_to_skip == 0);
540                 pkt = state->pkt;
541                 num_written = process_data(state, fh, pkt, state->num_bytes,
542                     pd, err, pid);
543
544                 if (num_written < 0) {
545                         return FALSE;
546                 }
547                 else if (num_written > 0) {
548                         *num_bytes = num_written;
549                         *direction = pkt->dir;
550                         return TRUE;
551                 }
552                 /* if 0 bytes written, keep processing */
553         } else {
554                 /*
555                  * We didn't have any data left over, so the packet will
556                  * start at the beginning of a record.
557                  */
558                 if (pid)
559                         pid->num_bytes_to_skip = 0;
560         }
561
562         /*
563          * That didn't get all the data for this packet, so process
564          * subsequent records.
565          */
566         while ((id = file_getc(fh)) != EOF) {
567                 state->offset++;
568                 switch (id) {
569                         case PPPD_SENT_DATA:
570                         case PPPD_RECV_DATA:
571                                 pkt = id == PPPD_SENT_DATA ? &state->spkt : &state->rpkt;
572
573                                 /*
574                                  * Save the offset of the beginning of
575                                  * the current record.
576                                  */
577                                 pkt->cd_offset = state->offset - 1;
578
579                                 /*
580                                  * Get the length of the record.
581                                  */
582                                 n = file_getc(fh);
583                                 n = (n << 8) + file_getc(fh);
584                                 state->offset += 2;
585
586                                 if (pkt->id_offset == 0) {
587                                         /*
588                                          * We don't have the initial data
589                                          * offset for this packet, which
590                                          * means this is the first
591                                          * data record for that packet.
592                                          * Save the offset of the
593                                          * beginning of that record and
594                                          * the offset of the first data
595                                          * byte in the packet, which is
596                                          * the first data byte in the
597                                          * record.
598                                          */
599                                         pkt->id_offset = pkt->cd_offset;
600                                         pkt->sd_offset = state->offset;
601                                 }
602
603                                 g_assert(num_bytes_to_skip < n);
604                                 while (num_bytes_to_skip) {
605                                         file_getc(fh);
606                                         state->offset++;
607                                         num_bytes_to_skip--;
608                                         n--;
609                                 }
610                                 num_written = process_data(state, fh, pkt, n,
611                                     pd, err, pid);
612
613                                 if (num_written < 0) {
614                                         return FALSE;
615                                 }
616                                 else if (num_written > 0) {
617                                         *num_bytes = num_written;
618                                         *direction = pkt->dir;
619                                         return TRUE;
620                                 }
621                                 /* if 0 bytes written, keep looping */
622
623                                 break;
624
625                         case PPPD_SEND_DELIM:
626                         case PPPD_RECV_DELIM:
627                                 /* What can we do? */
628                                 break;
629
630                         case PPPD_RESET_TIME:
631                                 wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err);
632                                 state->offset += sizeof(guint32);
633                                 state->timestamp = pntohl(&time_long);
634                                 state->tenths = 0;
635                                 break;
636
637                         case PPPD_TIME_STEP_LONG:
638                                 wtap_file_read_unknown_bytes(&time_long, sizeof(guint32), fh, err);
639                                 state->offset += sizeof(guint32);
640                                 state->tenths += pntohl(&time_long);
641
642                                 if (state->tenths >= 10) {
643                                         state->timestamp += state->tenths / 10;
644                                         state->tenths = state->tenths % 10;
645                                 }
646
647                                 break;
648
649                         case PPPD_TIME_STEP_SHORT:
650                                 wtap_file_read_unknown_bytes(&time_short, sizeof(guint8), fh, err);
651                                 state->offset += sizeof(guint8);
652                                 state->tenths += time_short;
653
654                                 if (state->tenths >= 10) {
655                                         state->timestamp += state->tenths / 10;
656                                         state->tenths = state->tenths % 10;
657                                 }
658
659                                 break;
660
661                         default:
662                                 /* XXX - bad file */
663                                 g_message("pppdump: bad ID byte 0x%02x", id);
664                                 *err = WTAP_ERR_BAD_RECORD;
665                                 return FALSE;
666                 }
667
668         }
669
670         *err = file_error(fh);
671         return FALSE;
672 }
673
674
675
676 /* Used to read packets in random-access fashion */
677 static gboolean
678 pppdump_seek_read(wtap *wth,
679                  long seek_off,
680                  union wtap_pseudo_header *pseudo_header,
681                  guint8 *pd,
682                  int len,
683                  int *err)
684 {
685         int             num_bytes;
686         direction_enum  direction;
687         pppdump_t       *state;
688         pkt_id          *pid;
689         int             num_bytes_to_skip;
690
691         state = wth->capture.generic;
692
693         pid = g_ptr_array_index(state->pids, seek_off);
694         if (!pid) {
695                 *err = WTAP_ERR_BAD_RECORD;     /* XXX - better error? */
696                 return FALSE;
697         }
698
699         if (file_seek(wth->random_fh, pid->offset, SEEK_SET, err) == -1)
700                 return FALSE;
701
702         init_state(state->seek_state);
703         state->seek_state->offset = pid->offset;
704
705         /*
706          * We'll start reading at the first record containing data from
707          * this packet; however, that doesn't mean "collate()" will
708          * stop only when we've read that packet, as there might be
709          * data for packets going in the other direction as well, and
710          * we might finish processing one of those packets before we
711          * finish processing the packet we're reading.
712          *
713          * Therefore, we keep reading until we get a packet that's
714          * going in the direction we want.
715          */
716         num_bytes_to_skip = pid->num_bytes_to_skip;
717         do {
718                 if (!collate(state->seek_state, wth->random_fh, err, pd,
719                     &num_bytes, &direction, NULL, num_bytes_to_skip))
720                         return FALSE;
721                 num_bytes_to_skip = 0;
722         } while (direction != pid->dir);
723
724         if (len != num_bytes) {
725                 *err = WTAP_ERR_BAD_RECORD;     /* XXX - better error? */
726                 return FALSE;
727         }
728
729         pseudo_header->p2p.sent = (pid->dir == DIRECTION_SENT ? TRUE : FALSE);
730
731         return TRUE;
732 }
733
734 static void
735 pppdump_close(wtap *wth)
736 {
737         pppdump_t       *state;
738
739         state = wth->capture.generic;
740
741         if (state->seek_state) { /* should always be TRUE */
742                 g_free(state->seek_state);
743         }
744
745         if (state->pids) {
746                 unsigned int i;
747                 for (i = 0; i < g_ptr_array_len(state->pids); i++) {
748                         g_free(g_ptr_array_index(state->pids, i));
749                 }
750                 g_ptr_array_free(state->pids, TRUE);
751         }
752
753         g_free(state);
754
755 }