SQLite Forum

no check for a failled malloc
Login
hello!

as subject says, it looks like you missed some malloc checks a few times.

* [here](https://github.com/sqlite/sqlite/blob/31aa366293757e845ddbe7742958d17f148b987a/src/window.c#L1073) `pSub` is dereferenced and unchecked. you may claim that allocation of `p->pSrc` is checked before and therefore there's no chance that `pSub` is not allocated but size of `struct SrcList` (which is `sizeof(*p->pSrc)`) is MUCH smaller than size of `struct Select` (which is `sizeof(*pSub)`) therefore one could succeed and one could not. to me it would be better if a condition on a [line 1069](https://github.com/sqlite/sqlite/blob/31aa366293757e845ddbe7742958d17f148b987a/src/window.c#L1069) would check state of the flag `db->mallocFailed`.

* [here](https://github.com/sqlite/sqlite/blob/31aa366293757e845ddbe7742958d17f148b987a/src/select.c#L354) you may see that `pE2` is unchecked. yeah, here it is _very unlikely_ that pE2 allocation would fail and pEq allocation would succeed because they have the same size but to me it looks like juggling with knives to some extent. to me it would also be better if in the condition on [line 350](https://github.com/sqlite/sqlite/blob/31aa366293757e845ddbe7742958d17f148b987a/src/select.c#L350) you would check for a flag `db->mallocFailed`