tools/graph2dot: Check for av_malloc() failure

Fixes CID1271047

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-02-22 22:43:06 +01:00
parent 704c980294
commit 0a32a1b4bb

View File

@ -157,9 +157,17 @@ int main(int argc, char **argv)
struct line *line, *last_line, *first_line; struct line *line, *last_line, *first_line;
char *p; char *p;
last_line = first_line = av_malloc(sizeof(struct line)); last_line = first_line = av_malloc(sizeof(struct line));
if (!last_line) {
fprintf(stderr, "Memory allocation failure\n");
return 1;
}
while (fgets(last_line->data, sizeof(last_line->data), infile)) { while (fgets(last_line->data, sizeof(last_line->data), infile)) {
struct line *new_line = av_malloc(sizeof(struct line)); struct line *new_line = av_malloc(sizeof(struct line));
if (!new_line) {
fprintf(stderr, "Memory allocation failure\n");
return 1;
}
count += strlen(last_line->data); count += strlen(last_line->data);
last_line->next = new_line; last_line->next = new_line;
last_line = new_line; last_line = new_line;
@ -167,6 +175,10 @@ int main(int argc, char **argv)
last_line->next = NULL; last_line->next = NULL;
graph_string = av_malloc(count + 1); graph_string = av_malloc(count + 1);
if (!graph_string) {
fprintf(stderr, "Memory allocation failure\n");
return 1;
}
p = graph_string; p = graph_string;
for (line = first_line; line->next; line = line->next) { for (line = first_line; line->next; line = line->next) {
unsigned int l = strlen(line->data); unsigned int l = strlen(line->data);