toolbox

Check-in [87d8a0bbf2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:retab: fix memory leak
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 87d8a0bbf27e85d5d5ec034e4623eb894d215b89a7a275be1719db8d8c63bd03
User & Date: jef 2020-05-01 11:44:23
Context
2020-05-01
14:22
retab: improve table_widths() check-in: c4678b759f user: jef tags: trunk
11:44
retab: fix memory leak check-in: 87d8a0bbf2 user: jef tags: trunk
08:42
retab: use struct to rearrange the code check-in: 7fcee8800c user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/retab/retab.c.

54
55
56
57
58
59
60
61

62

63
64
65
66
67
68
69
...
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
...
264
265
266
267
268
269
270
271
272
273
read_line(char **line)
{
	char *data = NULL;
	size_t linecap = 0;
	ssize_t res;

	res = getline(&data, &linecap, stdin);
	if (res == -1)

		return 0;


	str_trim(data);
	if (is_line(data) || is_row(data)) {
		*line = data;
		return 1;
	}

................................................................................
{
	char *line = NULL;
	jtlst *rows;
	jtlst *widths;
	struct row *row;

	rows = jtlst_new();
	while (read_line(&line))
		jtlst_append(rows, row_new(line));
	xfree(line);


	if (jtlst_size(rows) == 0)
		return;

	widths = table_widths(rows);
	if (widths == NULL)
		die("abort, table without rows");
................................................................................
			break;
		}
	}
	argc -= optind;
	argv += optind;

	retab();
	
	return EXIT_SUCCESS;
}







|
>

>







 







|

|
>







 







|


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
267
268
269
270
271
272
273
274
275
276
read_line(char **line)
{
	char *data = NULL;
	size_t linecap = 0;
	ssize_t res;

	res = getline(&data, &linecap, stdin);
	if (res == -1) {
		xfree(data);
		return 0;
	}

	str_trim(data);
	if (is_line(data) || is_row(data)) {
		*line = data;
		return 1;
	}

................................................................................
{
	char *line = NULL;
	jtlst *rows;
	jtlst *widths;
	struct row *row;

	rows = jtlst_new();
	while (read_line(&line)) {
		jtlst_append(rows, row_new(line));
		xfree(line);
	}

	if (jtlst_size(rows) == 0)
		return;

	widths = table_widths(rows);
	if (widths == NULL)
		die("abort, table without rows");
................................................................................
			break;
		}
	}
	argc -= optind;
	argv += optind;

	retab();

	return EXIT_SUCCESS;
}