Browse code

cid 12135/12134 - fix error state for allocating memory in pdf parsing

Kevin Lin authored on 2015/08/19 03:29:33
Showing 1 changed files
... ...
@@ -504,8 +504,14 @@ char *pdf_parse_string(struct pdf_struct *pdf, struct pdf_obj *obj, const char *
504 504
                     res = pdf_finalize_string(pdf, obj, begin, objsize2);
505 505
                     if (!res) {
506 506
                         res = cli_calloc(1, objsize2+1);
507
-                        if (!(res))
507
+                        if (!(res)) {
508
+                            close(fd);
509
+                            cli_unlink(newobj->path);
510
+                            free(newobj->path);
511
+                            newobj->path = NULL;
512
+                            free(begin);
508 513
                             return NULL;
514
+                        }
509 515
                         memcpy(res, begin, objsize2);
510 516
                         res[objsize2] = '\0';
511 517