mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
ExUtilInitCommandLineArguments: fix leak on error
argv_data would leak if the argv_ allocation failed or the MAX_ARGC cap was hit Tested: for i in `seq 1 171`; do export MALLOC_FAIL_AT=$i ./examples/img2webp jpeg_file -o /dev/null ./examples/img2webp -mixed jpeg_file -o /dev/null done Change-Id: I39864691e96d5456f324d95a3653bba0f6d6a7be
This commit is contained in:
parent
ec34fd7023
commit
2d3293ad76
@ -103,7 +103,10 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
|
|||||||
}
|
}
|
||||||
args->own_argv_ = 1;
|
args->own_argv_ = 1;
|
||||||
args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_));
|
args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_));
|
||||||
if (args->argv_ == NULL) return 0;
|
if (args->argv_ == NULL) {
|
||||||
|
ExUtilDeleteCommandLineArguments(args);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
argc = 0;
|
argc = 0;
|
||||||
for (cur = strtok((char*)args->argv_data_.bytes, sep);
|
for (cur = strtok((char*)args->argv_data_.bytes, sep);
|
||||||
@ -111,6 +114,7 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
|
|||||||
cur = strtok(NULL, sep)) {
|
cur = strtok(NULL, sep)) {
|
||||||
if (argc == MAX_ARGC) {
|
if (argc == MAX_ARGC) {
|
||||||
fprintf(stderr, "ERROR: Arguments limit %d reached\n", MAX_ARGC);
|
fprintf(stderr, "ERROR: Arguments limit %d reached\n", MAX_ARGC);
|
||||||
|
ExUtilDeleteCommandLineArguments(args);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
assert(strlen(cur) != 0);
|
assert(strlen(cur) != 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user